Cancels the pending entry, order or exit orders that carry an id, before they fill.
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
strategy.cancel(id: series string) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | series string | required | The id of the order to cancel, as given to strategy.entry, strategy.order or strategy.exit. |
Returns
Nothing.
Remarks
- Calling
strategy.entrywith the same id replaces the pending order and is simpler when you only want to move the price. - Only available in strategy scripts.
Example
//@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