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
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

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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:
The other method that I've tried to use is via curtime: