OnInit() and OnTimer() to count second

 

Hi,

I try to increase my variable secondCounter in every second, does my code here work?

And both of these function still won't work in Strategy Tester, am I right?

int secondCounter = 0;

int OnInit()
{
   EventSetTimer(1);
   return(INIT_SUCCEEDED);
}

void OnTimer()
{
   secondCounter++;
}
Thanks.
 
thanhnguyen1911: And both of these function still won't work in Strategy Tester, am I right?
Nope, OnInit always works.
 
thanhnguyen1911: I try to increase my variable secondCounter in every second, does my code here work?

And both of these function still won't work in Strategy Tester, am I right?

Thanks.

Just in case you are using MT4/MQL4 (and not MT5/MQL5), and you have posted in the wrong section, please note that Timer events are NOT simulated in MT4's Strategy Tester.

Event Handling in the Tester

The following events are handled in the Strategy Tester: initializing an Expert Advisor before a single run of OnInit(), deinitializing an Expert Advisor after a single run of OnDeInit() and simulating a new tick OnTick().

In addition, Tester event handled in OnTester() function is generated before calling OnDeInit() deinitialization function after testing a trading robot on historical data. The value returned by this function is used as a Custom max criterion when optimizing the input parameters.

Timer and ChartEvent events are not handled in the Strategy Tester