This diagnostic strategy submits one long order on a chosen bar index, freezes its price and gives it three subsequent bars to fill. If still pending at the third close, it cancels the order. A filled position gets a timed market exit only to complete the test. There is no trading signal or protective stop. Use a standard candlestick chart and a symbol whose price and contract value fit the test capital.
Pine v6 lifecycle example. P marks submission and X marks cancellation. The blue line retains the requested price; the Data Window exposes pending state.pinescript
//@version=6
strategy("One limit order lifecycle", overlay = true, initial_capital = 100000, pyramiding = 0, commission_type = strategy.commission.percent, commission_value = 0.1, slippage = 1, backtest_fill_limits_assumption = 0, process_orders_on_close = false, calc_on_every_tick = false, calc_on_order_fills = false, use_bar_magnifier = false)
submitBar = input.int(100, "Submission bar index", minval = 0)
offsetTicks = input.int(4, "Buy offset in ticks", minval = 1)
expiryBars = input.int(3, "Pending lifetime in bars", minval = 1)
holdBars = input.int(2, "Bars after observing the fill", minval = 1)
var float limitPrice = na
var int submittedBar = na
var int observedFillBar = na
var bool pending = false
bool submitted = false
bool cancelled = false
if bar_index == submitBar and strategy.position_size == 0
limitPrice := math.round_to_mintick(close - offsetTicks * syminfo.mintick)
if limitPrice > 0
strategy.entry("L", strategy.long, qty = 1, limit = limitPrice)
submittedBar := bar_index
pending := true
submitted := true
if pending and strategy.position_size > 0
pending := false
observedFillBar := bar_index
if pending and bar_index - submittedBar >= expiryBars
strategy.cancel("L")
pending := false
cancelled := true
if strategy.position_size > 0 and bar_index - observedFillBar == holdBars
strategy.close("L")
plot(limitPrice, "Requested limit", color = color.blue, style = plot.style_linebr)
plot(bar_index, "Bar index", display = display.data_window)
plot(pending ? 1 : 0, "Pending at calculation", display = display.data_window)
plotshape(submitted, title = "Submitted", text = "P", style = shape.labelup, location = location.belowbar, color = color.blue, textcolor = color.white)
plotshape(cancelled, title = "Cancelled", text = "X", style = shape.labeldown, location = location.abovebar, color = color.orange, textcolor = color.black)