Bug in Security code

 

Hello dear developer.

I am an upcoming and improving developer.

I have the below piece of code that I use to protect my mt4 and mt5 indicator and ea but presently it is not working on mt4.

I have tried to fix it but could not.

Please help me with the issue so that it can work on mt4 again.

Thanks

//------------ START SECURITY CODE -----
//1-COPY THE CODE BETWEEN ABOVE 'START SECURITY CODE' AND BELOW 'END SECURITY CODE' TREATED LINES
//2-AND ADD IT TO PROGRAM YOU WANT TO LOCK
//3-THEN ADD 'security()' JUST AFTER OnTick(){ or OnCalculate(){ FUNCTIONS 
//  AND/OR JUST AFTER OnInit(){ FUNCTION
input string Password="";
void security()
{bool remove=false;
 string PasswordSecurity="202221";//NULL=disabled
 int UserAccountNumber=22512591;//0=disabled
 datetime ExpirationDate=D'2023.10.05';//0=disabled / Date format-> D'yyy.mm.dd hh:mm' or simply D'yyyy.mm.aa' 
 ENUM_TIMEFRAMES WorkingTimeFrame=PERIOD_CURRENT;//PERIOD_CURRENT=All timeframes allowed
 string WorkingPair[]={"Volatility 75 Index"};//Empty value ("") will allow all symbols. 
                         //To define use comma separator, for instance {"EURUSD","GBPUSD","..."}
 string alertstr[]={NULL,NULL,NULL,NULL};       
 if(UserAccountNumber!=0 && UserAccountNumber!=AccountInfoInteger(ACCOUNT_LOGIN) && AccountInfoInteger(ACCOUNT_LOGIN)!=0)
 {alertstr[0]="Wrong account number"; remove=true;}
 if(ExpirationDate!=0 && (TimeCurrent()>=ExpirationDate||TimeLocal()>=ExpirationDate))
 {alertstr[1]="Indicator has been expired"; remove=true;}
 if(WorkingTimeFrame!=0 && WorkingTimeFrame!=Period())
 {alertstr[2]="Time frame is not right"; remove=true;}
 if(ArraySize(WorkingPair)>1)
 {bool cond=false;
  for(int i=0;i<ArraySize(WorkingPair);i++)
  {if(Symbol()==WorkingPair[i])cond=true;}
  if(!cond){alertstr[3]="Pair is not right"; remove=true; }
 }
 if(PasswordSecurity!=NULL && Password!=PasswordSecurity){
   Alert("Wrong password ! Enter right password");
   remove=true;
 }
 if(remove)
 {if(MQLInfoInteger(MQL_PROGRAM_TYPE)==PROGRAM_EXPERT || MQLInfoInteger(MQL_PROGRAM_TYPE)==PROGRAM_SCRIPT)
  {ExpertRemove();}          
  else{string indnm="thisIndicator";
      IndicatorSetString(INDICATOR_SHORTNAME,indnm);
      for(int i=(int)ChartGetInteger(ChartID(),CHART_WINDOWS_TOTAL)-1;i>=0;i--)
         ChartIndicatorDelete(ChartID(),i,indnm);
      //ChartRedraw();
      }
 }
 //else Alert("Program started !");
 for(int i=0;i<4;i++){
   if(alertstr[i]!=NULL)Alert(alertstr[i]);
 }
}
//---------- END SECURITY CODE -----
 
Abraham:

I have the below piece of code that I use to protect my mt4 and mt5 indicator and ea but presently it is not working on mt4.


Don’t create multiple duplicate threads.

How do you expect help when you don’t say what the expected behaviour is and what errors you are getting?

 
Paul Anscombe #:

Don’t create multiple duplicate threads.

How do you expect help when you don’t say what the expected behaviour is and what errors you are getting?

I am sorry for the duplicate. Very sorry. Thanks.

Initially, when i set the needed parameters like the password, account number, pairs, timeframe, etc and compile the code either in ea or indicator, the indicator or ea will function just inline with the command I input in the security code e.g if I bind the ea or indicator to an account it will work on that account only, if I bind it to certain pairs or timeframe, or set password for it, such indicator or ea will not work if those parameters are missing.

It does not compile and it gives error in the attached image below

I do use the code on mt4 and mt5 but recently it stopped functioning on mt4. I have tried within my knowledge to fix it to no avail.

Your assistance in fixing the error will be so much appreciated.

Thanks.

Files:
 
Abraham #:
It does not compile and it gives error in the attached image below

Because you are compiling without #property strict.

Add #property strict

 

https://docs.mql4.com/basis/mql4changes

Old MQL4 compiler

New MQL4 compiler

New MQL4 with #property strict

...

...

...

Variable scope is from declaration (even in the nested block) to the function end

Ditto

Variable scope is from declaration to the end of the block, in which the variable is declared

 
Vladislav Boyko #:

Thanks.

I did add the  #property strict but many other issues came up.

Attached is the image of errors it brought after adding  #property strict.

Files:
 
Abraham #:

I did add the  #property strict but many other issues came up.

Other errors/warnings are related to your other code. The code you posted compiles without errors or warnings.