Problems with the strategy tester...

 

Hi all,


I just coded my first EA: I can test it on my demo account in the "live trading" mode without problems, but when I try to use the strategy tester, the progress bar is stuck and the testing process never completes. Can you please tell me what's wrong with this code?


If I look at the "Journal" from within the strategy tester to debug it, it looks like the RefreshRates() call in my canOpenTrade() function could be the problem -- apparently, it always yields FALSE on historic data in the WHILE cycle that calls Sleep(5) and then RefreshRates()! Why does it do that? It works like it should in live trading mode, what's the problem here? Can you help me fix it?


The reference guide for RefreshRates() says the only reason data cannot be refreshed (= returns FALSE) is that they are already the current data of the client terminal.


After doing more debugging, it looks like the Sleep(5) has no effect: the time doesn't seem to pass at all in the historic data, it's stuck! Same thing if I put, say, Sleep(10000). That would explain why RefreshRates() always returns FALSE. But why am I always stuck at the same moment in the historic data?


Can you help me debug this?

Thanks!


bool canOpenTrade() {
   int i = 0;
   double val2, std;

   Alert("Testing the market...");
   while(i < NUM_TICKS_FOR_TREND) { // only if the trend doesn't change for at least N ticks
      Sleep(5);
      if(RefreshRates() == True) {
         val = updateVal(0);
         val2 = updateVal(1);
         i++;
         if(val*val2 < 0) {
            if(i > 5)
               Alert("Unstable market (i = ", i, "/", NUM_TICKS_FOR_TREND,")");
            i = 0;
         }
      }
   }
   std = iStdDev("EURUSD", 1, STDDEV_PERIOD, 0, 0, 0, 0);
   if(std >= MIN_STDDEV)
      return(True);
   else {
      Alert("Can\'t open trade, stddev(", STDDEV_PERIOD,") is only ", std);
      return(False);
   }
}
Files:
 
The strategy tester is kind of buggy when it comes to certain while loops. You can opt out of while loops with https://docs.mql4.com/check/IsTesting .
 
jmca:
The strategy tester is kind of buggy when it comes to certain while loops. You can opt out of while loops with https://docs.mql4.com/check/IsTesting .

Thank you jmca. So I can use IsTesting() to detect when i'm in testing mode, but what can I do to substitute the while() loop? Recursion, maybe? You said this only happens with a certain kind of while loops, can you tell me on which kind so that I can try and edit the while loop code without resorting to recursion?


thanks again

Reason: