MT4 strategy tester seems to skip data

 

I'm experiencing a very strange phenomenon. I developed an EA which runs once per bar, since it uses data of the last finished bar. During backtesting it behaved strange, so I stripped it's code to the following:


datetime LastCoreTime;

int OnInit()

{

   return INIT_SUCCEEDED;

}


void OnTick()

{

   if( !AlreadyRunHere() ) {

      Print("--- iTime = ", iTime(NULL,0,1), ";  Open/Close = ", iOpen(NULL,0,1), " / ", iClose(NULL,0,1));

   }

}

bool AlreadyRunHere()

{

bool ret = (Time[0]==LastCoreTime) ;

   if( !ret ) LastCoreTime = Time[0];

   return ret;

}

I run the backtest from 2019.01.01 to 2019.03.31. on H1 timeframe with EURUSD symbol. I set model to "every tick". 

However if I examine the log, it prints hourly bar Open and Close times nicely from (going backwards in time) 2019.03.29. 21:00 all the way back to 2019.03.18. 10:00, then it displays a datetime of 2019.01.21. 16:00 , then continues nicely hourly prints until 2019.01.21. 09:00 and no prints before that at all.

That is interval of 01.01 - 01.21 and 01.21 - 03.18 are completely missing from the test.

Before this test I re-installed MT4 clean (from Activtrades) and downloaded EURUSD H1 data from the broker. Checking History Center, all H1 data are fine and there, no gaps in the chart, etc. etc.


What happens here?

 

OK, guys, I got the answer (a bit humbling...)

When I posted my problem, the forum put a couple of topic below mine to suggest topics like mine. And one of them lead to this article: https://www.mql5.com/en/docs/runtime/testing

This is a good article and it turned out, that the cause of the phenomenon was simply just how Print(...) behaves. During strategy tester, MT4 simply cannot handle all my Print requests and some of them just did not appear in the log. That's it. So no data is missing, I just did not get printouts for them. 

When I changed my Print(...) to FileWrite(...), suddenly all printouts appeared, so everything is fine.

I feel a bit like a beginner fool, but I got this resolved and this is what matters. :-)

Documentation on MQL5: MQL5 programs / Testing Trading Strategies
Documentation on MQL5: MQL5 programs / Testing Trading Strategies
  • www.mql5.com
The idea of automated trading is appealing by the fact that the trading robot can work non-stop for 24 hours a day, seven days a week. The robot does not get tired, doubtful or scared, it's is totally free from any psychological problems. It is sufficient enough to clearly formalize the trading rules and implement them in the algorithms, and...
 

Sabc237:  if I examine the log,

Don't look at the log tab, as not all entries are there. Look at the actual log file. Log tab → Right click → Open will flush the log to disk and open explorer.

 

Thanks! 

I learned it the hard way. :-)

Reason: