Download MetaTrader 5

How to protect my EA with multiple account number

To add comments, please log in or register
sakibco
107
sakibco  
int liveAccountNumber = 535621;
int liveAccountNumber2 = 737213;

if(( AccountNumber()  liveAccountNumber) && ( AccountNumber()  liveAccountNumber2))

Hello, I am trying to do in this way but it is not working for the second or multiple account number. I want to get a code that will allow my EA only for some accounts. If the account number do not match between two or more accounts then EA will not work.

Please, help me to do this. Advice me the correct code.Thanks in advanced.

Taras Slobodyanik
20232
Taras Slobodyanik  
long login=AccountInfoInteger(ACCOUNT_LOGIN);
try this
sakibco
107
sakibco  
Taras Slobodyanik:
try this

Would you please explain me a little, where and how to use this code?
Meng Yin Teoh
1723
Meng Yin Teoh  
int liveAccountNumber = 535621;
int liveAccountNumber2 = 737213;

int start() {
if(( AccountNumber() == liveAccountNumber) || ( AccountNumber() == liveAccountNumber2))
{
   Print("Account Number recognized.thanks");
   Alert("Account Number recognized.");
   return(1);
}
else
{
   Print("Account Number not recognized.");
   Alert("Account Number not recognized,Contact EA author to validate account");
   return(-1);
}
}
Your if logic is incorrect. I've made the changes for you.
nerverlost
19
nerverlost  
Meng Yin Teoh:
Your if logic is incorrect. I've made the changes for you.
these is work for me... very nice.thank you Meng...
nicholishen
1090
nicholishen  

There is a better way to do this... Add as few or many account numbers to an array with an initialization list and then iterate over the list to find a matching account number. 

void OnStart()
{
   int my_acc = (int)AccountInfoInteger(ACCOUNT_LOGIN);
   //--- add as many accounts as necessary -- example-
   int auth_accounts[] = { 123456, //live 1
                           123457, //live 2
                           123458, //demos
                           123459,
                           123444
                         };
   bool is_auth = false;
   for(int i=0;i<ArraySize(auth_accounts);i++)
      if(auth_accounts[i] == my_acc)
         is_auth = true;
 
   if(!is_auth)
      Print("Account not authorized!");
   else
      Print("Your account is authorized");
}
Mladen Rakic
65815
Mladen Rakic  
sakibco:

Would you please explain me a little, where and how to use this code?

And what code are you going to "protect" when you are not familiar with a simple function that returns account number usage ?

Summer :) Always the same ... :)

To add comments, please log in or register