Hi All,
I'm trying to have my EA pause after a deal was closed so that he does not re-open a position for "x" amount of candles.
I tried to achieve that using the pause function but when back testing it seems like the pausing is not applied.
Is there another way I could do that, that would work with back testing ?
Don't use Sleep() to perform this kind of function, Sleep() cannot work in the Strategy Tester. Instead save the time to a variable (e.g. LastOrderTime) and only place new Orders when the required time has passed . .
Note: This is not Copy & Paste code, please read understand and do your own implementation.
datetime LastOrderTime; bool OKToTrade = true; // last order placed here OKToTrade = falsee; // set the variable to remember when the last order was placed LastOrderTime = TimeCurrent() // check if the required time has elapsed if(TimeCurrent() > LastOrderTime + PauseLength) OKToTrade = true

- www.mql5.com
Hi Raptor !!
Thanks a lot for your help !
Based on your suggestions I created the follow code. But as per below screenshot my int with "PauseTime" is not being added properly to LastOrderTime.
I'm pretty sure this is a "format" problem ? PauseTime should also be a datetime or just time ?
input int PauseTime=6; // Pause Length in Hours
Print ("Last order Time is: ",LastOrderTime); Print ("Last order Time + Pause is: ",LastOrderTime + PauseTime); if (Pause){ if(TimeCurrent() > LastOrderTime + PauseTime){ EAStatus="Trading"; } else{ if(TimeCurrent() < LastOrderTime + PauseTime){ EAStatus="Taking a Pause"; return; } } } EAStatus="Trading";
Hi Raptor !!
Thanks a lot for your help !
Based on your suggestions I created the follow code. But as per below screenshot my int with "PauseTime" is not being added properly to LastOrderTime.
I'm pretty sure this is a "format" problem ? PauseTime should also be a datetime or just time ?
See what doc says about datetime (... the number of seconds elapsed since January 01, 1970), so if you want to add 37 minutes, do this :
datetime thirty_seven_minutes = 37*60; Print(TimeCurrent() + thirty_seven_minutes);
You know, you can just continue from your last topic Sleep EA during a fix time of the day
Hi Raptor !!
Thanks a lot for your help !
Based on your suggestions I created the follow code. But as per below screenshot my int with "PauseTime" is not being added properly to LastOrderTime.
I'm pretty sure this is a "format" problem ? PauseTime should also be a datetime or just time ?
TimeCurrent() returns a datetime so for simplicity make everything a datetime. As phi.nuts points out a datetime is the number of seconds since Midnight 1st Jan 1970 but you might want to consider that definition only applying to a datetime that represents a date. The distinction is an important one . . .
datetime thirty_seven_minutes = 37*60;
is not a date unless it is meant to represent 1st Jan 1970 00:37 but is a valid datetime none thee less as it is a number of seconds, using very meaningful variables names will help make your code clear and easy to document. If your variable is a date use date in the variable name, if it is a number of seconds, minutes or hours use sec, min or hr in the variable name.
To express 6 hours use a datetime set to 6 * 60 * 60, in mql4 this was easy we could say 6 * PERIOD_H1 * 60 but the mql5 constants don't mean the same thing.
Hi phi.nuts!!
You did it again :) Here is the working code in my case if someone needs it it. And yes I could have continued on my other topic!
datetime PauseTime = PauseHours*3600; if (Pause){ if(TimeCurrent() > LastOrderTime + PauseTime){ EAStatus="Trading"; } else{ if(TimeCurrent() < LastOrderTime + PauseTime){ EAStatus="Taking a Pause"; return; } } } EAStatus="Trading";

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi All,
I'm trying to have my EA pause after a deal was closed so that he does not re-open a position for "x" amount of candles.
I tried to achieve that using the pause function but when back testing it seems like the pausing is not applied.
Is there another way I could do that, that would work with back testing ?