Closes the whole open position with a market order on the next bar, whatever entry ids opened it.
strategy.close_all() flattens the position. Like strategy.close, it sends a market order that fills at the next bar's open, or at the current bar's close when process_orders_on_close is true or immediately is true.
It affects only open trades; pending entry, limit and stop orders stay in place, so use strategy.cancel_all() as well when you want a clean slate.
Syntax
strategy.close_all(comment: series string (optional), alert_message: series string (optional), immediately: series bool (optional), disable_alert: series bool (optional)) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| comment | series string | an empty string | Text shown next to the order on the chart and in the list of trades. |
| alert_message | series string | an empty string | Text sent as {{strategy.order.alert_message}} in an alert created on the strategy when this order fills. |
| immediately | series bool | false | When true, the order fills at the close of the current bar instead of the open of the next one. |
| disable_alert | series bool | false | When true, an alert on the strategy does not fire for this order's fill. |
Returns
Nothing.
Remarks
- A common use is an end-of-day exit: close_all on the last bar of the session.
- Only available in strategy scripts.
Example
//@version=6
strategy("Day trade", overlay = true, process_orders_on_close = true)
if session.isfirstbar
strategy.entry("Long", strategy.long)
if session.islastbar
strategy.close_all(comment = "end of day")
bgcolor(session.islastbar ? color.new(color.red, 85) : na)See also
Runs on Sidechair