You can never sell at the close. You can only sell at the open after the close!
If you enter mid candle with a limit or stop order then this will close the trade on the same candle (well the following open at least). Otherwise if your strategy bought at the open then it will sell at the close (or following open really) of the candle after the decision candle – the same one that you entered on.
Just start counting bars from the moment you decide you want to exit after x bars or save the barindex and and exit when barindex equals your saved value plus however many bars.
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.