account number lock MQL5

 

Hello


I have added a code to my EA MQ5 but it doesn't work .

could you please correct me .

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");
 
Oussama Mansour it doesn't work . could you please correct me .

There's nothing wrong with your posted code except that ACCOUNT_LOGIN returns a possible long and you are using an int.
          Constants, Enumerations and Structures / Environment State / Account Properties - Reference on algorithmic/automated trading language for MetaTrader 5

 
Comments that do not relate to this topic, have been moved to "Off Topic Posts".
 
Oussama Mansour:

Hello


I have added a code to my EA MQ5 but it doesn't work .

could you please correct me .

I believe it's a Script, not an EA, because of OnStart function, you need to put your code in OnTick function.
 
Mohammad Hossein Sadeghi:
I believe it's a Script, not an EA, because of OnStart function, you need to put your code in OnTick function.

If it is put in OnTick() it should be coded to only carry out the check once.

Otherwise there will be a lot of prints.

 
Keith Watford:

If it is put in OnTick() it should be coded to only carry out the check once.

Otherwise there will be a lot of prints.

Yes, indeed. But OnStart for EA is never called.
 
Mohammad Hossein Sadeghi:
Yes, indeed. But OnStart for EA is never called.

I wasn't disputing that.

 
Keith Watford:

I wasn't disputing that.

Yes, maybe OP was not aware that event handling function matters.

 

Seems like an ego discussion loool

 
Alain Verleyen:

Seems like an ego discussion loool

It's already finished.
Reason: