Don't use sleep(). Monitor the trade server time (i.e. TimeCurrent) and detect when at least one hour has passed.
When you need to start the countdown, set a static variable to the current time plus the delay duration, and then when the current time is beyond that value, you can resume normal operations again.
![Documentation on MQL5: Date and Time / TimeCurrent Documentation on MQL5: Date and Time / TimeCurrent](https://c.mql5.com/36/60/documentation-on-mql5-date-and__1.png)
- www.mql5.com
Don't use sleep(). Monitor the trade server time (i.e. TimeCurrent) and detect when at least one hour has passed.
When you need to start the countdown, set a static variable to the current time plus the delay duration, and then when the current time is beyond that value, you can resume normal operations again.
Don't use sleep(). Monitor the trade server time (i.e. TimeCurrent) and detect when at least one hour has passed.
When you need to start the countdown, set a static variable to the current time plus the delay duration, and then when the current time is beyond that value, you can resume normal operations again.
- also like that .. its dont work when i use OrderType() function
if(LastClosed("Type" )==OP_SELL) { Sleep(36000000); }
i wana build EA with Sleep() Function to delay 1 hour between each trades ..but i dont know why its dont work
- can somme one slove it plz??
if(LastClosed("CloseTime")==TimeCurrent() )
{
Sleep(36000000);
}
Often order close time won't match TimeCurrent. that is why it doesn't works.
instead do that:
if(TimeCurrent() < LastClosed(ORDER_CLOSE_TIME) + 3600) return;
Also avoid using strings. Use enumerations as parameters and switch statement instead of if on your LastClosed() function.
Often order close time won't match TimeCurrent. that is why it doesn't works.
instead do that:
Also avoid using strings. Use enumerations as parameters and switch statement instead of if on your LastClosed() function.
thanks friend for u advice
but i wana using Sleep() function coz its work with milliseconds ,, and i will use milliseconds in other EA
Sleep(1000)=1 Second
https://docs.mql4.com/common/sleep![Sleep - Common Functions - MQL4 Reference Sleep - Common Functions - MQL4 Reference](https://c.mql5.com/36/60/sleep-common-functions-mql4-referen.png)
Why do you insist on working with sleep in milliseconds if your delay is for one hour?
Also, using sleep should only be used for very short delays, because it blocks the thread and no other events can be processed by the EA (tick events, chart events, time events, etc.).
MQL programs are event driven and if you block the processing for too long it will hang them. Do it properly as explained above. Use sleep only very small delays (a few seconds at most).
EDIT: Even for a short delays, I prefer monitoring the tick data for the millisecond time stamp, so as not to block event processing on the thread. I NEVER use sleep at all, especially because it does not work on Indicators.
Why do you insist on working with sleep in milliseconds if your delay is for one hour?
Also, using sleep should only be used for very short delays, because it blocks the thread and no other events can be processed by the EA (tick events, chart events, time events, etc.).
MQL programs are event driven and if you block the processing for too long it will hang them. Do it properly as explained above. Use sleep only very small delays (a few seconds at most).
EDIT: Even for a short delays, I prefer monitoring the tick data for the millisecond time stamp, so as not to block event processing on the thread. I NEVER use sleep at all, especially because it does not work on Indicators.
The reason it does not work has already been explained to you in post #4 by @Samuel Manoel De Souza.
And I quote ... "Often order close time won't match TimeCurrent. that is why it doesn't works."
But you ignored his statement without considering it.
The reason it does not work has already been explained to you in post #4 by @Samuel Manoel De Souza.
And I quote ... "Often order close time won't match TimeCurrent. that is why it doesn't works."
But you ignored his statement without considering it.
thanks friend for u advice
but i wana using Sleep() function coz its work with milliseconds ,, and i will use milliseconds in other EA
Sleep(1000)=1 Second
https://docs.mql4.com/common/sleep![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
i wana build EA with Sleep() Function to delay 1 hour between each trades ..but i dont know why its dont work
if(LastClosed("CloseTime")==TimeCurrent() )
{
Sleep(36000000);
}