'Pine Script Fill Stop Order Only If Stop Price Was Reached Before Stop Loss
I'm building a strategy using Pine Script Version 5.
I'm trying to create a stop order using strategy.order command.
The command is working as expected and executes on the next candle if the stop price was reached.
The only issue is that as part of my strategy, the order should be filled only if the price reached the stop price before the intended stop loss price, which means that if the price reaches the stop loss price, it should cancel the stop order and not fill it.
This issue happens only when back-testing, because TradingView does not calculate the intra-bar ticks, on live it will either fill the order or cancel it, but when backtesting it will fill the order even if the high of the candle broke above the intended stop loss price.
I'm trying to find a way to solve it as in the current state the backtest produces false results.
If there is a way to read the future candles (only on history bars) this would solve my issue, but I didn't find a way to do it.
Help would be appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
