Please edit your post to use the CODE button (Alt-S)!
The open time of the current bar:
#define BoB(t) ((t)-((t)%(PeriodSeconds(_Period)))) // Begin of Bar .. datetime tOpn = BoB(TimeCurrent());
now the time to close:
tLeave = tOpn + PeriodSeconds(_Period) - n; // n= amount of seconds
so if there are tick coming in:
if (TimeCurrent()>tLeave) closeMyPosition();
i am trying to get it to close the trade on the candle it entered in but it seems to only be calling the closing fucntion at the start of the next candle any idea why it is doing this?
The function to close a position is part of ..Trade\Trade.mqh
Open Trade.mqh in the Editor and look how it is done and how you can use the function.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi i am trying to close my trade before the start of the new candle but have been unsuccessful so far , any help/advice is appreciated.