Trouble backtesting with the Sleep function

 
Hello,

The logic that I've been trying to implement in my Expert requires a time delay of several hours after I enter a trade (once I enter a trade, I want the Expert to totally ignore whatever happens to the currency for a few hours, then upon waking from its sleep, it will take action). I've tried to use the Sleep function in MT4, but my EA continues to ignore it. I've also tried to implement the delay by using (curtime+delay), but I can't seem to get MT to successfully pass the time-- I have the expert perform some simple meaningless calculations, but the expert never gets to the end of the delay.

By any chance am I getting the Sleep code messed up? Or is my other code messed up? Thanks for any help anybody can offer.
-Melchior


The Expert calls the SleepCycle function whenever my logic requires it:
void SleepCycle()
  {
   RecentOpen=1;
   int DelaymS;
   DelaymS=DelayHours*3600*1000; //Hours*60(min/h)*60(sec/min)*1000(millisec/sec)
   Sleep(DelaymS); 
   return;
  }



The other method that I've tried to use is via curtime:

void SleepCycle()
  {
   RecentOpen=1;
   int DelaymS;
   DelaymS=DelayHours*3600*1000; //Hours*60(min/h)*60(sec/min)*1000(millisec/sec)
   double current_time;
   current_time=CurTime()+DelaymS/10000;
   while (CurTime()<current_time)
     {
       //Simple calculations go here, max out my CPU, and don't get my backtests very far...
     }
   return;
  }
 
Sleep does not work when testing. delays are not modelled. see "Testing Features and Limits in MetaTrader 4"
 
I would note the time of the order / trade as a global variable and then just ignore while the server time < order time + delay.

Or, if you have only one trade open for the strategy, look at the time of that trade, add your interval, and compare it to the server time.

hope it helps,

regards
Reason: