DocsActionClose All Positions

Close All Positions

ExitAction

Close All Positions issues a market close on every open trade simultaneously when the connected signal becomes truthy. It is the broadest exit primitive — ideal for kill-switch scenarios, end-of-session flat rules, or emergency risk responses that need to clear the entire portfolio in one step.

How It Works

  1. 1

    Connect any boolean or numeric signal to the node's input port.

  2. 2

    On each tick, the node reads the last non-null value from the signal. If it is non-zero, triggered is set to true.

  3. 3

    When triggered, a close command is dispatched for every position tracked by the position state manager — not just the most recently opened one.

  4. 4

    If no positions are open, the node is a no-op and produces no side effects.

Parameters

No configurable parameters.

Inputs & Outputs

PortTypeDescription
Input
inputsignalTrigger signal. Non-zero last value closes all open positions.
Outputs
triggeredbooleantrue when the close-all command fired on the last tick.
lastSignalValuenumber | nullThe last non-null value read from the input.

Use Cases

End-of-session flat rule

Wire a time signal that fires at 15:55 each day to guarantee no overnight exposure, closing all open longs and shorts simultaneously.

Volatility kill-switch

Connect a VIX spike detector or ATR threshold breach signal. If market volatility explodes beyond tolerance, the node empties the book immediately.

Portfolio drawdown guard

Compute a rolling drawdown metric and trigger Close All when portfolio equity drops more than X% from peak — automatic catastrophic-loss prevention.

Tips

Scope vs Close Position. Close Position targets only the single active position tracked by its paired Open Position node. Close All Positions targets every position in the position-state manager — prefer it for portfolio-wide exits.
Signal debounce. Because the signal fires on every tick it is truthy, consider adding a one-bar latch (Rising Edge / Edge Detect node) so the close command is sent only once per event.
Backtesting. In backtesting mode the node correctly marks all simulated positions as closed at the current bar's close price with slippage applied per position.

Related Nodes