ProBacktest/probacktest · proorder

QUIT

QUIT in ProBacktest and ProOrder immediately stops a trading system, closing open positions and cancelling pending orders. Syntax and restart caveats.

Syntax

probuilder
QUIT

How it works

When execution reaches a QUIT statement, the trading system shuts down on that bar. Any open position is closed at market, all pending stop and limit orders are cancelled, and the strategy stops processing further bars. The shutdown is final from the code's point of view: no instruction can restart a stopped system, so resuming trading requires relaunching the strategy manually from the platform.

In ProBacktest the effect is the same in simulation. The test ends on the bar where QUIT executes and the remaining history is ignored, which is useful for modelling a hard capital limit.

QUIT is almost always wrapped in a condition. The usual patterns are an equity floor read from STRATEGYPROFIT, a shutdown time read from the clock constants such as CurrentHour, or a position-state guard built from ONMARKET, LONGONMARKET, or SHORTONMARKET. It acts as the last line of defense after per-trade protections such as stops and targets.

Examples

Example 1, Shut down at 22:00 while short (ProOrder)

probuilder
// Stop the system at 22:00 if a short position is still open
IF ShortOnMarket AND CurrentHour = 22 THEN
  QUIT
ENDIF

At the first bar of the 22:00 hour with a short position open, the position is closed and the system stops. This is the first example from the official reference.

Example 2, Equity kill switch (ProOrder)

probuilder
// Terminate the strategy once it has lost 200 units of account currency
IF StrategyProfit < -200 THEN
  QUIT
ENDIF

STRATEGYPROFIT tracks the cumulative result of the system. Once the loss exceeds 200 currency units, QUIT flattens the book and halts trading permanently.

Example 3, Drawdown limit from the equity peak (ProBacktest)

probuilder
// Track the equity high-water mark
ONCE peakEquity = 0
equity = StrategyProfit
IF equity > peakEquity THEN
  peakEquity = equity
ENDIF

// Stop the test after a 500-unit drawdown from the peak
IF peakEquity - equity >= 500 THEN
  QUIT
ENDIF

Instead of a fixed loss floor, the kill switch fires on a drawdown measured from the best equity reached, a common way to model a fund-style risk limit in a backtest.

Common errors and gotchas

  • No programmatic restart. Once QUIT executes, the system is stopped for good. There is no instruction that re-arms it; restarting means relaunching the strategy manually. A condition that fires too easily can silently take a live system offline.
  • Exit at market, with slippage. QUIT closes the open position at market price. In fast conditions the fill can be noticeably worse than the last quoted price, so the realized loss can exceed the threshold that triggered the shutdown.
  • Unconditional QUIT stops on the first bar. Placed outside any IF block, QUIT executes immediately and the strategy never trades. It must always sit behind a condition.
  • Truncated backtests skew statistics. In ProBacktest, QUIT ends the simulation early. Comparing runs where one version quits halfway through the data against a version that runs to the end is not a like-for-like comparison; check the number of bars actually traded.
  • STRATEGYPROFIT, cumulative profit of the system in account currency.
  • CurrentHour, hour of the current bar, useful for timed shutdowns.
  • ONMARKET, true while any position is open.
  • SHORTONMARKET, true while a short position is open.
  • LONGONMARKET, true while a long position is open.
  • FLATAFTER, forces the strategy flat after a given time each day.
  • FLATBEFORE, forces the strategy flat before a given time each day.
  • SELL, closes an open long position.
  • EXITSHORT, closes an open short position.