Help me with this code.

 

I need to create a custom Demo version for my EA.,  so I used the OnTesterInt(); function and update a flag if the EA was loaded to strategy tester. but the code doesn't works as expected. What I did wrong here?. 

bool OnTeseter = false;

int OnInit()
  {   
   if(TimeCurrent() < ExpireTime) // If Time is true
   {
    if(OnTeseter == true) // Demo Version.
    {
      BarsTotal = iBars(NULL, PERIOD_M5); // update the bars total
      SetChart();
      
      TesterHideIndicators(true); // Hides indicators on teseter. 
      
      Print("Expert has loaded succesfully");
      return(INIT_SUCCEEDED); 
     }
     else
     {
      MessageBox("This is a Demo version. Only works on the \"Stratergy Tester\"","Invalid Chart",MB_OK);
      return(INIT_FAILED);
     }
   }
   else
   {
   Comment("Expiration Date And Time - :", TimeToString(ExpireTime,TIME_DATE|TIME_MINUTES));
   return(INIT_FAILED);   
   }
  }

void OnTesterInit()
{
 OnTeseter = true; // Update the flag. 
}

void OnTesterDeinit()
{

}
 
Well, what DOES it do then? Is this the whole code? What value is Expire time?
 
Tobias Johannes Zimmer #:
Well, what DOES it do then? Is this the whole code? What value is Expire time?

It wasn't the whole code. it the part that doesn't work as expected. btw, I found the answer. 

This is the correct line of code to achieve that.  

datetime ExpireTime = __DATETIME__ + PeriodSeconds(PERIOD_D1) *30  // 30d from the compiled date
string ExpireMsg = "The EA has been expired since" + TimeToString(ExpireTime,TIME_DATE|TIME_MINUTES); 

// OnInt function --------+++++ ----------- 
int OnInit()
  {
   if(TimeCurrent() < ExpireTime) // Not Expired
     {
      if(MQLInfoInteger(MQL_TESTER) == true) // Check the EA is on the strategy tester.
        {
                        
         return(INIT_SUCCEEDED);
        }
      else
        {
         PlaySound("Alert.wav");
         MessageBox("This is a Demo version. Only works on the \"Strategy Tester\". Purchase the \"Paid Version\" to unlock the Expert Advisor.  ","Invalid Chart",MB_OK);

         return(INIT_FAILED);
        }
          
     }
   else
     {
      PlaySound("Alert.wav");    
      MessageBox(ExpireMsg,"Expired...!",MB_OK);
      return(INIT_FAILED);
     }
  }

 
Hapu Arachchilage Tharindu Lakmal #:

It wasn't the whole code. it the part that doesn't work as expected. btw, I found the answer. 

This is the correct line of code to achieve that.  

Nice thank you

 

You can simply use this:

if(MQLInfoInteger(MQL_TESTER)==true) // do things in test mode...