Sidechair

strategy.cancel()

Browse the reference

Cancels the pending entry, order or exit orders that carry an id, before they fill.

Try it in the editor

strategy.cancel(id) removes every pending order named id. Orders that have already filled are not affected. It takes effect for the next bar's order processing, so an order cancelled on bar N does not fill on bar N+1.

Use it when the reason for a limit or stop order goes away, for example a pullback entry whose trend condition has failed.

Syntax

Pine Script
strategy.cancel(id: series string) -> void

Arguments

NameTypeDefaultDescription
idseries stringrequiredThe id of the order to cancel, as given to strategy.entry, strategy.order or strategy.exit.

Returns

Nothing.

Remarks

  • Calling strategy.entry with the same id replaces the pending order and is simpler when you only want to move the price.
  • Only available in strategy scripts.

Example

Pine ScriptWithdraw a stale limit orderOpen in editor
//@version=6
strategy("Cancel on failure", overlay = true)
trendUp = close > ta.sma(close, 50)
if trendUp
    strategy.entry("Dip", strategy.long, limit = low)
else
    strategy.cancel("Dip")
bgcolor(trendUp ? color.new(color.green, 92) : na)

See also

Runs on Sidechair