Account Lock problem

 

Hi everyone


Could someone please assist with the following. I'm new to coding and are trying to lock my EA so that it will only run on a specific account in order for it not to be copied over. I have attached my code but for some reason its not working. If I add my EA onto a chart it still works even if the account number is the wrong one. Please advise as where i have gone wrong. I managed to set up the expired date setting bit I'm struggling with the account block . I know how to add a password but it will not work for me since the password can just be given to the next person and my EA will still be copied. I have entered th code into my Ontick in my EA and I'm not sure if it is correct.

void OnTick()
  {
int my_acc = (int)AccountInfoInteger(ACCOUNT_LOGIN);
   
   int auth_accounts[] = { 123456, 
                           123457, 
                           123458, 
                           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");
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
 
  1. “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. (2004)
              When asking about code
              Be precise and informative about your problem

  2. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

 
As I have explained in my first comment I have done the code as seen by the input and I receive no error message but when I add my expert to a chart on an account then it does not restrict the expert from running on the wrong account as it still loads normal and runs. 
 
Dawid Zinserling #:
As I have explained in my first comment I have done the code as seen by the input and I receive no error message but when I add my expert to a chart on an account then it does not restrict the expert from running on the wrong account as it still loads normal and runs. 

Your code is simply checking the account number and printing a message, there is no code shown that will restrict access or remove the expert from the chart?  

ACCOUNT_LOGIN is a long data type

also don't run security checks in OnTick it is a massive waste of resources

Try using https://www.mql5.com/en/docs/common/expertremove

Documentation on MQL5: Common Functions / ExpertRemove
Documentation on MQL5: Common Functions / ExpertRemove
  • www.mql5.com
ExpertRemove - Common Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Dawid Zinserling #: As I have explained in my first comment I have done the code as seen by the input and I receive no error message but when I add my expert to a chart on an account then it does not restrict the expert from running on the wrong account as it still loads normal and runs. 

You were already given example code to study ... https://www.mql5.com/en/forum/444251#comment_45847990

If you were unable to understand it or adapt it to your needs, then there is not much more we can do for you. You may need to hire someone in the Freelance section to do it for you.

 
Thank you very much guys. Will fix it once I get home.
Reason: