Help with code

 
Can you step through the code? I'm getting a value incorrect (see below "Account") and then its being corrrectly populated but i'm not sure why.

int Account = 123456;

if (Account != AccountNumber())
{
Comment("You can not use this program with this account");
return (0);
}
else
{
Comment("Welcome to Program");
}
 
Try This:

int Account = 123456; 

if (Account != AccountNumber())
{
Comment("You can not use this program with this account");
}
else Comment("Welcome to Program");



 
Without return 0 the program will continue.
 
Your right.

int Account = 123456; 

if (Account != AccountNumber())
{
Comment("You can not use this program with this account");
return(0);
}
else Comment("Welcome to Program");
 
You gave me the same thing I originally gave you. I can't see the difference of what I gave you.

Thanks
 
The difference is the set of {} around the else function.

If you are intending to protect you EA from unauthorized use, you might consider this:


int ApprovedCode = 123456;
extern int AccessCode= 0; // you give authorized users ApprovedCode number to enter here.

if (AccessCode!= ApprovedCode)
{
Comment("You can not use this program with this account");
return(0);
}
else Comment("Welcome to Program");
 
Thanks not what I was looking for.

I want to know why the function 'AccountNumber()' is not returning the
correct value or any value for a second or two.
 
I use to use this method to protect my EAs.

Your EA only starts running after each tick or price change. When you attach your EA to a chart it can sometimes take a few seconds or even minutes before price changes and MT4 runs your EA. Try using the following code to protect your EA. The difference is that when the account numbers match the EA will no longer call the AccountNumber() function. Running the function every time before your code will produce a small delay which can sometimes cause a problem when price is moving quickly and your EA needs to make a decision (open, modify or close and order).


#define ACCOUNT_NUMBER 123456
bool EAJustStarted=true;

int init()
  {
   return(0);
  }
int deinit()
  {
   return(0);
  }
  
int start()
{

if(EAJustStarted==true)
   {
      if(AccountNumber()!=ACCOUNT_NUMBER)
      {
         Comment("You can not use this program with this account");
         return(0);
      } 
      EAJustStarted=false;
   }

return(0);
}




I want to know why the function 'AccountNumber()' is not returning the
correct value or any value for a second or two.



 
Robinhood,

Thanks for the code. However I am trying to protect an indicator, not an EA. Will this work for an indicator as well.

Thanks
Rich
 
Yes, it works with indicators too.


Best regards,
Glenn
Reason: