strategy.cancel() - Pine Script Function
strategy.cancel()
Section titled “strategy.cancel()”Overview
Section titled “Overview”Cancels a pending or unfilled order with a specific identifier. If multiple unfilled orders share the same ID, calling this command with that ID as the id argument cancels all of them. If a script calls this command with an id representing the ID of a filled order, it has no effect.
Syntax
Section titled “Syntax”strategy.cancel(id) → voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| id | series string | The identifier of the unfilled order to cancel. |
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6strategy(title = "Order cancellation demo")conditionForBuy = open > high[1]if conditionForBuystrategy.entry("Long", strategy.long, 1, limit = low) // Enter long using limit order at low price of current barif `conditionForBuy` is `true`.if not conditionForBuystrategy.cancel("Long") // Cancel the entry order with name "Long"if `conditionForBuy` is `false`.