Strategy test freezes

 

Hi,

my Expert Advisor freezes the strategy tester. I already noticed that the strategy tester does not like "Sleep()" so I changed that to:


sleepUntil=TimeCurrent()+1;
while(sleepUntil>TimeCurrent())
{
//Do nothing

}


to sleep for 1 second. It works fine live but the strategy tester never returns from the while(). When I "Print()" the TimeCurrent() in the loop I can see that it never changes.

Why is that so and what can I do about it?

thanks

 

Umm, MT4/MQL4 is a tick-based system, driven by when ticks come in (which incidentally I expect also sets TimeCurrent).

By doing a loop like you are, you are not letting MT4 get the next TimeCurrent !

I suggest something along the lines of

static datetime OnlyProcessOnceForThisSecond = 0;
if(TimeCurrent() == OnlyProcessOnceForThisSecond)
  return;
OnlyProcessOnceForThisSecond = TimeCurrent();

Actually, I suggest you don't do anything of the sort, but I don't know why you would possibly not want to process another tick within a second of the last one, in what might be a fast moving market.

Please think hard about why you want MT4 to wait at least one second before processing a tick event.

 

You have to return, you can't use an infinite loop in the tester.

Why do you want an infinite loop anyway? start is called when something changes.

You should exit the loop on chart shutdown

while (!(IsTesting() || IsStopped()) )
 
Oh thank you. I got it all wrong. I thought the "start()" is called only once but it is like a "DoFrame()" in a game-engine. It´s working for me now, thanks.
Reason: