Close All
On this page
Use [[close_all]] to close any open market position, on both the Long and Short sides.
Unlike the standard [[close]] block, which targets a specific entry through its order_id value, [[close_all]] closes the entire current position.
By default, after requesting the close, the block validates on the current candle and the next block is evaluated immediately. The wait_candles key only delays this transition.
Block declaration
A strategy can contain multiple [[close_all]] blocks.
Examples
Minimal close all
This example closes the entire open position.
[[close_all]]
id = "flatten_all"
next_block_id = "next_condition"Immediate execution
This example requests immediate execution when possible (intrabar), without changing block chaining behavior.
[[close_all]]
id = "emergency_exit"
immediately = true
next_block_id = "next_condition"Comment for export
This example adds a custom signal label for trade list display and Pine Script export.
[[close_all]]
id = "shutdown"
comment = "Strategy Stopped"
next_block_id = "next_condition"Block parameters
| Parameter | Description |
|---|---|
idText Required | Unique identifier for the block. |
next_block_idText Required | Identifier of the block executed next. |
immediatelyBoolean Optional | If set to true, forces [[close_all]] to execute on the current candle, regardless of process_orders_on_close. If set to false and process_orders_on_close = false, the close executes on the next eligible candle.This parameter does not change wait_candles.Default value: false |
wait_candlesInteger Optional | Number of candles to wait before validating the block and moving to the next one. Use 0 to disable the delay.Default value: 0 |
commentText Optional | Populates the Signal column in the trade list. If omitted, the signal defaults to Close All. Also exported as the Pine Script comment. No impact on backtest calculations. |
alert_messageText Optional | This parameter has no effect on backtests. It is only used to set the Pine Script alert_message parameter. |