Cancels every pending order of the strategy: entries, orders and exits that have not filled.
strategy.cancel_all() clears the order book. Open trades stay open; only waiting orders are removed.
Pair it with strategy.close_all() to leave the market completely.
Syntax
strategy.cancel_all() -> voidReturns
Nothing.
Remarks
- Only available in strategy scripts.
- Pending
strategy.exitorders are removed too, so an open position loses its stop and target. Callstrategy.exitagain on a later bar if the position stays open.
Example
//@version=6
strategy("Cancel all at the close", overlay = true)
if session.isfirstbar
strategy.entry("Buy stop", strategy.long, stop = high + syminfo.mintick)
if session.islastbar
strategy.cancel_all()
strategy.close_all()
bgcolor(session.islastbar ? color.new(color.gray, 85) : na)See also
Runs on Sidechair