Have you tried using the Sleep() function?
void Sleep( int milliseconds)
The Sleep() function suspends execution of the current expert within the specified interval.
The Sleep() function cannot be called from custom indicators since they calculate in the interface thread and may not decelerate it.
The checking of the expert stop flag status every 0.1 second has been built into the function.
Parameters:
milliseconds - Sleeping interval in milliseconds.
Sample:
//---- wait for 10 seconds
Sleep(10000);
Hope this helps
Have you tried using the Sleep() function?
void Sleep( int milliseconds)
The Sleep() function suspends execution of the current expert within the specified interval.
The Sleep() function cannot be called from custom indicators since they calculate in the interface thread and may not decelerate it.
The checking of the expert stop flag status every 0.1 second has been built into the function.
Parameters:
milliseconds - Sleeping interval in milliseconds.
Sample:
//---- wait for 10 seconds
Sleep(10000);
Hope this helpsThanks, wolfe.
I thought about it.
Ideally i dont want EA to suspend execution, just not to start new trades
euro
You can try this.
/////////////////////////////////////////////////////////////////////////////////////////
// DO NOT PLACE AN ORDER IF WE JUST CLOSED
// AN ORDER WITHIN Period() MINUTES AGO
/////////////////////////////////////////////////////////////////////////////////////////
datetime orderclosetime;
string rightnow;
int rightnow2;
int TheHistoryTotal=HistoryTotal();
int difference;
int flag=0;
for(cnt=0;cnt<TheHistoryTotal;cnt++)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY)==true) //check history
{
if ( (OrderSymbol()==Symbol()) && (OrderMagicNumber() == MagicNumber) ) // only symbol and magic
{
orderclosetime=OrderCloseTime();
rightnow=Year()+"-"+Month()+"-"+Day()+" "+Hour()+":"+Minute()+":"+Seconds();
rightnow2=StrToTime(rightnow);
difference=rightnow2-orderclosetime;
if(Period()*60*2>difference)
{ // At least 2 periods away!
flag=1; // Throw a flag
break;
}
}
}
}
if(flag!=1)
{
Your code condition here
}
OrderCloseTime()
ejoi,
interesting code, thanks.
I managed to write a couple of lines of code that do the trick
If my EA is profitable you will have some royalties,
- 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 run an EA and sometimes need to Close an Order manually.
My EA immediately opens another Order, which i dont want.
Really, I need a time interval between closing one order and EA opening another. I was trying to use OrderCloseTime() to get last order close time, but either my code is incorrect or there is a bug in this MQ4 function.
OrderCloseTime() works only if there is significant time between ticks.
Anybody resolved similar problem or knows how to do it in MQ4?
Thanks,
euro