Solution for Pine script – close order before end of candle?
is Given Below:
My stop loss seems to only be executed at the close of the candle. Since it’s based on Low/High, it would be sound to be executed as soon as the high/low appears. Is there a possibility to do this?
// Determine stop loss price lowest(exit_slow) slowLC = lowest(10) slowSC = lowest(10) longStopPrice2 = slowLC shortStopPrice2 = slowSC //exit long if (strategy.position_size > 0) //and not (notcapitulation and momentumL and choppyL) strategy.exit(id="StopLimit", stop=longStopPrice2, comment="CLOSE", alert_message="STOP")//CloseComment CloseCommentAlert strategyClose := true //exit short if (strategy.position_size < 0) strategy.exit(id="StopLimit", stop=shortStopPrice2, comment="CLOSE", alert_message="STOP") strategyClose := true
I of course don’t want to use future data so the backtesting remains sound.
Currently when I check the backtesting orders, even the STOP orders are executed exactly at 4h close times.