Sleep() function does not work

 

Hello,

I tried to use the Sleep() function in my EA but it is not working as expected.

I even put it into the start() function at the beginning but I get log-entries for every single tick.

int start()
{
   Sleep(10000); // sleep for 10seconds, but should sleep forever
   
   Print("Please fall asleep!"); // Prints every tick

   return(0);
}
 
coolex:

Hello,

I tried to use the Sleep() function in my EA but it is not working as expected.

I even put it into the start() function at the beginning but I get log-entries for every single tick.


I do this to run every minute (it works) in my EA:

timeWaiting = TimeMinute(TimeLocal());
while (TimeMinute(TimeLocal()) == timeWaiting){
Sleep(100);
}
RefreshRates();

Test this:

timeWaiting = TimeSeconds(TimeLocal())+10;
while (TimeSeconds(TimeLocal()) <= timeWaiting){
Sleep(100);
}
RefreshRates();

 
But why is the Sleep() function not working in my case? What is the reason? Can't I test Sleep() in the StrategyTester?
 
coolex:
But why is the Sleep() function not working in my case? What is the reason? Can't I test Sleep() in the StrategyTester?


My problem was the execution of sleepfunction was not accurate. I only use the sleepfunction, so that MT4 not freeze in a while-loop. Now the while-loop measures time.

I´m a newbie, but I guess that the sleep, function in "StrategyTester" is disabled. It would be logical to disable the sleep-function while backtesting...

I wish you the best and I hope a "Guru" will pick up this topic and give you the correct answer!

 
try to recompile your EA/restart the terminal
 
I tried to recompile and restarted the terminal but still the same results.
 

try

int start()
{
   Alert (TimeToStr(TimeLocal(),TIME_SECONDS));
   Sleep(10000); // sleep for 10seconds
   Alert (TimeToStr(TimeLocal(),TIME_SECONDS));
   
   return(0);
}

& c what happens

 
IntraTrade:
I´m a newbie, but I guess that the sleep, function in "StrategyTester" is disabled. It would be logical to disable the sleep-function while backtesting...
Sleep doesn't work in the tester
int start(){
   static datetime delayTime;
   if (TimeCurrent() < delayTime) return;
   :
   if (condition){
       delayTime = TimeCurrent()+ 60; return; // wait a minute
   }