How do i code “sell at next candle”, in other words sell at the next candle close no matter what
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.
if onmarket then
sell at market
endif
What about “exit after X bars”, possible to code? 🙂
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.