1. What type of somebars ? integer, double, or what ?
2. Why you have year 2005 ?
3. To find out whether your sleep is working or not, use GetTickCount() .
OrderSend(Symbol(),OP_SELL,LotsOptimized,Bid,3,0,0,"",MAGICMA,0,Blue);
sellopentime=TimeCurrent();
Print(GetTickCount());
Sleep(3600000);
Print(GetTickCount());
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: open #2 sell 0.10 EURAUD at 1.68452 ok
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: 39567265
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: 39567265
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: close #2 sell 0.10 EURAUD at 1.68452 at price 1.68475
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: open #3 sell 0.10 EURAUD at 1.68457 ok
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: 39567265
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: 39567265
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: close #3 sell 0.10 EURAUD at 1.68457 at price 1.68462
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: open #4 sell 0.10 EURAUD at 1.68444 ok
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: 39567265
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: 39567265
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: close #4 sell 0.10 EURAUD at 1.68444 at price 1.68448
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: open #5 sell 0.10 EURAUD at 1.68430 ok
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: 39567265
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: 39567265
00:31:15 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: close #5 sell 0.10 EURAUD at 1.68430 at price 1.68459
still like this. seems nothing refer to somebars. why Sleep() don't work?
yes, i do F1 to see the function of sleep in dictionary.
it says the sleep() function do suspend trade in the parameter time.
for example Sleep(10000); means wait for 10 seconds.
however, still no useful like above. so strange.
Not like that
int start = GetLastError(); Sleep(3600000); Print(GetTickCount()- start);
Probably they ignore sleep in backtesting. Try in demo forward testing, with smaller sleep like 1000 (1 second) or 10000 (10 seconds) so you don't have to wait too long.
BTW 3600000 miliseconds is 1 hour, there's plenty of ways to get orders opened 1 hour later - not just using sleep :)
here example to run after one hour later
int now; // we can use integer or datetime type (https://docs.mql4.com/dateandtime) but must be global variable so EA remember int count_tick; int init () { count_tick = GetTickCount(); return(0); } int start() { if (TimeLocal() >= now + 240) // we use either TimeLocal() or TimeCurrent() { Print (GetTickCount () - count_tick); now = TimeLocal(); count_tick = GetTickCount(); // the action code } return(0); }
:) yes, it meas 1 hour. i just want to sleep 1 or 2 bars that is why int somebars made. 1 hour is good time for my dinner. thanks for your suggestion. i will try in demo. if still awake not sleep, i have to change my EA.
you're correct. sleep work in demo but not in backtest. thanks.
In that case, hope this works on backtesting
int now; // we can use integer or datetime type (https://docs.mql4.com/dateandtime) but must be global variable so EA remember int count_tick; int init () { count_tick = GetTickCount(); return(0); } int start() { if (now <= Time [1]) // 1 hour later { Print (GetTickCount () - count_tick); now = Time[0]; count_tick = GetTickCount(); // the action code } return(0); }
- heyigeng:
the orders still open one by one immediately! why?Sleep doesn't work in the tester Testing Features and Limits in MetaTrader 4 - MQL4 Articles
count_tick = GetTickCount();
GetTickCount won't work in the tester

- 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,
i do Sleep() in EA, why no useful?
somebars=(Period()*60*1000);
OrderSend(Symbol(),OP_SELL,LotsOptimized,Bid,3,0,0,"",MAGICMA,0,Blue);
Sleep(somebars);
Print(TimeCurrent());
but-----------------------
23:49:48 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: open #7 sell 0.10 EURAUD at 1.68435 ok
23:49:48 2005.02.04 10:24 ϵͳ1-3-7 EURAUD,H1: 1107512690
23:49:48 2005.02.04 10:25 ϵͳ1-3-7 EURAUD,H1: close #7 sell 0.10 EURAUD at 1.68435 at price 1.68480
23:49:48 2005.02.04 10:25 ϵͳ1-3-7 EURAUD,H1: open #8 sell 0.10 EURAUD at 1.68460 ok
23:49:48 2005.02.04 10:25 ϵͳ1-3-7 EURAUD,H1: 1107512700
23:49:48 2005.02.04 10:25 ϵͳ1-3-7 EURAUD,H1: close #8 sell 0.10 EURAUD at 1.68460 at price 1.68487
23:49:48 2005.02.04 10:25 ϵͳ1-3-7 EURAUD,H1: open #9 sell 0.10 EURAUD at 1.68467 ok
23:49:48 2005.02.04 10:25 ϵͳ1-3-7 EURAUD,H1: 1107512705
23:49:48 2005.02.04 10:25 ϵͳ1-3-7 EURAUD,H1: close #9 sell 0.10 EURAUD at 1.68467 at price 1.68485
23:49:48 2005.02.04 10:25 ϵͳ1-3-7 EURAUD,H1: open #10 sell 0.10 EURAUD at 1.68465 ok
23:49:48 2005.02.04 10:25 ϵͳ1-3-7 EURAUD,H1: 1107512710
the orders still open one by one immediately! why?