Wait for a new bar

 

Hi,


I want my expert to wait 1 candle after entering a trade to look for exit conditions. The way I tried to implement this in my code was the following :


....

ticket = ordersend(...)

if(ticket != -1)

Sleep(Period()*60000)


Check exit conditions.....


It doesn't seems to work in backtesting mode (I didn't try in live yet). Is there a known compatibility problem with the function Sleep and the Backtest mode ? Or is my code wrong ?


Thanks

 

in the start function

Now=TimeCurrent();

TicketAge = (Now-TicketDate)/60;

if (TicketAge>=(Period()*1)) // 1 or the number of bars you want to pass

{

*your code what you want to do if the order is older than one minute or you period*

}


in the ordersend function,

if (ordersend ==success)

{

TicketDate=TimeCurrent(); // remember the time when the order is opened, you can also use one of the Order***() funtions, but i prefer this

}
 

I don't know the direct answer to your question, but this seems to work for me:

curBarTime      = iTime(curSymbol,curPeriod,0);
if (curBarTime == prevBarTime) return;
else                           prevBarTime = curBarTime;



 

FFT

IIRC, Sleep doesnt work when backtesting, so use a Time based method to be sure

-BB-

Reason: