this Sleep() ....

 

Hello forum,

It saw some issues in the past with Sleep(), but before I move on to alternatives (eg https://www.mql5.com/en/articles/1558 ) I am also not sure I got it right. Two issues:

1) In this EA I want to delay the buy/sell signal by 5 seconds, so under the MyEntrySignal() function I wrote something like below, but there is no delay so I'm surely missing something...

if (ConditionToBUY) {
	Sleep (5000); 
	return (SignalBUY);
} 

2) If I am using the Sleep() function in one of two EA's with the same Magic number - will the sleep affect both EAs or just his home EA?

Any insight ~most welcome!!!

Dan

 
Sleep only effects the EA from which it is called. If you use this in the Strategy Tester you should be aware that some functions are " processed/passed without output " in the Strategy tester . . . Sleep() is one of them, more info here: Testing Features and Limits in MetaTrader 4 - MQL4 Articles
 
  1. If you use Bid and Ask then you MUST call RefreshRates() after the Sleep().
  2. If you want the delay to work in the tester try:
    int start(){
        static datetime delay; if (TimeCurrent() < delay) return(0);
        static int      next;  if (next == SignalBUY){
            next = SignalNone;
            int ticket = OrderSend(...
        }
        else{
           :
           if (ConditionToBUY) {
               next = SignalBuy;  delay = TimeCurrent() + 5; // 5 seconds
           }
        }
    }

Reason: