Counting Candles

 

I have some code that depends on the number of candles that have elapsed since a trade was opened.

I set a global variable when a position is opened

First_Pos_time=Time[0];

Then when the next position is opened i calculate the number of candles that have elapsed by

Exit_MA_Shift= MathRound((Time[0]-First_Pos_time)/60/Time_Frame);

where Time_Frame=15 for a 15 minute chart.

So Exit_MA_Shift should equal the number of candles that have elapsed since the first trade was opened.

It seems to work, except when it goes over the weekend. Does anyone have an idea how I can exclude the time over the weekend from the candle calculation, and know when to do it.

Thanks

surveyman

 

Try using iBarShift() function with previous order open time (OrderOpenTime()) for time parameter.

https://docs.mql4.com/series/iBarShift

 
wackena:

Try using iBarShift() function with previous order open time (OrderOpenTime()) for time parameter.

https://docs.mql4.com/series/iBarShift


Hey,

Thanks a lot, I knew it would be something simple.

Cheers!