Risk Management

Drawdown Limits and Kill Switches for Deriv Bot Risk Control

· 9 min read

A drawdown-based circuit breaker is a hard, automatic rule that stops a Deriv bot when equity falls by a defined percentage from its running peak. It is implemented by tracking peak equity and current equity in the bot’s state, evaluating the ratio on every balance update received over the WebSocket, and setting a persistent halt flag that blocks all new contract purchases until a human deliberately resets it. This article specifies the threshold definitions, the wiring into the trade loop, and the recovery procedure, so you can implement a configurable kill switch in DBot blocks or in a standalone bot using the Deriv API.

Trading involves significant risk and you can lose your entire stake. Test every strategy on a demo account first.

Defining the peak and the threshold

Drawdown is only meaningful relative to a reference point. The first design decision is what “peak” means, and the answer must be written down before the bot runs, because changing it mid-session invalidates every prior measurement.

The standard definition is peak-to-trough on account equity: let P be the highest equity observed since the breaker was armed, and E the current equity. Drawdown is (P − E) / P. The breaker fires when this fraction exceeds a configured limit L. Equity here means the account balance reported by the platform, not the sum of open position values; for Multipliers, unrealised profit and loss move the balance, so the reported balance already reflects open risk. For fixed-stake contracts, the stake is deducted at purchase, so the balance reflects the maximum loss at the moment of entry. This is the correct conservative behaviour: the breaker sees the worst case immediately rather than waiting for settlement.

Two variants are worth distinguishing. A session drawdown resets its peak when the bot is restarted or the trading day rolls over. A lifetime drawdown never resets and is the stricter control. ORSTAC’s premise is that the maximum loss is defined before the expected gain, so the lifetime variant is the default recommendation, with the session variant as a secondary, earlier-warning layer.

The threshold itself should be chosen from the strategy’s own tested drawdown distribution, not from a round number. If a backtest on a large sample shows a maximum drawdown of 12% and you set the breaker at 15%, you are asserting that live behaviour will not exceed the tested envelope by more than three points. That assertion may be wrong. A breaker set slightly above the tested maximum is a filter against regime change, not a guarantee.

A second parameter is required: a minimum number of observations before the breaker can fire, or a minimum equity baseline. Without it, a bot that starts with a tiny balance can trip on a single losing contract and never trade. Set the peak only after the first balance update and require at least one completed contract before evaluation.

Wiring the breaker into the WebSocket trade loop

The Deriv API delivers balance and contract updates over a WebSocket subscription. The breaker must be evaluated on the same event stream that drives trading decisions, and it must be evaluated before any purchase call, not after.

The ordering matters. A typical loop receives a balance update, checks strategy conditions, and calls `buy`. If the breaker check is placed after the strategy check but before `buy`, a balance update that crosses the threshold will block the purchase in the same tick. If it is placed only on a timer, there is a window in which the bot can buy after the limit is breached. Evaluate on every balance message and re-check immediately before `buy` as a belt-and-braces measure.

The halt flag must be persistent across process restarts. Store it outside the bot’s memory, in a file or a small database, together with the peak value, the timestamp, and the reason for the halt. A bot that forgets it was halted and resumes on restart is not a circuit breaker; it is a suggestion.

Pseudo-code for the core logic:

state = load_state()          # peak, halted, halt_reason, contracts_settled
on_balance(equity):
    if state.peak is null:
        state.peak = equity
    state.peak = max(state.peak, equity)
    if state.contracts_settled < MIN_OBSERVATIONS:
        return
    dd = (state.peak - equity) / state.peak
    if dd >= LIMIT and not state.halted:
        state.halted = true
        state.halt_reason = "drawdown " + dd
        persist(state)
        cancel_open_subscriptions_if_policy_requires()
before_buy():
    if state.halted: reject
    if (state.peak - current_equity) / state.peak >= LIMIT: halt; reject
    proceed

In DBot, the equivalent is a numbered block sequence rather than code. The platform’s block interface does not expose a native drawdown block, so the logic is assembled from variables and conditions:

  1. On bot start, load the persisted peak and halt flag from a storage block or initialise them as empty.
  2. On every balance update, compare the current balance with the stored peak; if higher, overwrite the peak.
  3. Compute drawdown as (peak − balance) / peak using a maths block.
  4. If drawdown is greater than or equal to the limit and the settled-contract counter is at or above the minimum, set the halt flag and persist it.
  5. Wrap the purchase logic in a condition that requires the halt flag to be false.
  6. On restart, read the halt flag first; if true, do not enter the trade loop at all.

Whether DBot’s storage blocks survive a full restart depends on the platform version and how the bot is run; verify this on a demo account before relying on it. If persistence is unavailable, the safe fallback is to treat every restart as a reason to require manual re-arming.

One more wiring detail concerns open positions. A breaker that halts new purchases does not close existing contracts. For fixed-stake contracts, the stake is already committed and the outcome is determined at expiry, so there is nothing to close; the breaker’s job is to prevent the next stake. For Multipliers, positions can be closed, and the policy must state explicitly whether the breaker closes them or merely blocks new ones. Closing at the moment of maximum drawdown locks in the loss; leaving them open exposes the account to further loss. Neither is universally correct, but the choice must be written into the rule set.

Worked example

Consider a demo account with an initial balance of 1,000 USD, a drawdown limit of 10%, and a minimum of five settled contracts before the breaker can fire. Stakes are fixed at 10 USD per contract, consistent with the 1% ceiling on a 1,000 USD balance.

The bot settles five contracts and loses all five. Balance after five losses: 1,000 − (5 × 10) = 950 USD. The peak is 1,000 USD. Drawdown is (1,000 − 950) / 1,000 = 0.05, or 5%. The breaker does not fire; the minimum observation count is met but the threshold is not.

The bot continues. It loses five more contracts. Balance: 950 − 50 = 900 USD. Drawdown: (1,000 − 900) / 1,000 = 0.10, or 10%. The breaker fires. New purchases are blocked. The remaining balance of 900 USD is intact and the halt flag is persisted.

Now suppose the operator resets the breaker and re-arms it with the peak set to the current balance of 900 USD rather than the original 1,000 USD. This is a material change to the rule set and must be recorded as such. With the peak at 900 USD and the same 10% limit, the next halt occurs at 900 × 0.90 = 810 USD, a further loss of 90 USD. The total loss from the original 1,000 USD would then be 190 USD, or 19%. Re-arming from a lower peak does not restore the original protection; it redefines it. The correct procedure, if the strategy is to continue at all, is to treat the reset as a new configuration with its own recorded rationale and a fresh demo sample.

Note also what the example does not show: a winning contract. If the balance rises to 1,050 USD after the first five losses, the peak updates to 1,050 USD and the drawdown is measured from there. The breaker tracks the high-water mark, not the starting balance, which is why a strategy that grinds upward and then reverses can trip at an equity level that is still above the initial deposit.

Recovering safely after a halt

A halt is not an inconvenience to be cleared as quickly as possible. It is a signal that the assumptions behind the strategy’s risk envelope have been violated. Recovery should be a process, not a button press.

The first step is diagnosis before reset. Compare the realised drawdown with the tested drawdown distribution. If the live drawdown is within the tested range, the breaker may simply be set too tight relative to the strategy’s normal behaviour, and the correct change is to the threshold, documented and re-tested. If the live drawdown exceeds the tested maximum, the strategy is behaving outside its envelope, and the correct response is to stop, not to adjust the limit upward. Raising a breaker immediately after it fires is the same error as doubling a stake after a loss, expressed in configuration rather than in money.

The second step is a demo re-run. ORSTAC’s position is that real money is used only after a recorded demo sample and with minimum stake. A halt resets that requirement. Run the strategy on a demo account with the revised configuration for a sample large enough to be informative, and record the drawdown observed. Do not treat the demo result as risk-free evidence of future behaviour; it removes financial risk but not behavioural or execution differences, and the demo feed may differ in fill behaviour from live.

The third step is re-arming with an explicit record: the new peak, the new limit if changed, the reason, and the date. Version the rule set. Changes follow a process — hypothesis, test, version — and never happen right after a loss, when the temptation to “fix” the configuration is strongest.

A useful recovery rule is that re-arming requires a human action that cannot be automated by the bot itself. If the bot can clear its own halt flag, the breaker is only a delay.

Limitations

This approach does not protect against gap risk or slippage on Multipliers, where the realised loss can exceed the drawdown measured at the moment of the check. It does not protect against platform outages, API disconnections, or a bot process that fails between the balance update and the persistence write. It does not prevent losses within a single contract beyond the stake for fixed-stake products, and it cannot make a negative-expectancy strategy positive. It does not substitute for the other hard limits ORSTAC recommends: daily loss caps and consecutive-loss counters operate on different timescales and catch different failure modes. It also does not address martingale-style progressions, which can produce drawdowns that arrive faster than any balance-driven check can react; any progression needs a hard cap on steps and stake and a ruin test before going live. Finally, the breaker’s correctness depends entirely on the peak being persisted; a bot that loses its state on restart has no breaker at all.

Frequently Asked Questions

Should the drawdown limit be a percentage of the peak or a fixed currency amount?

A percentage of the peak is preferable because it scales with the account and remains meaningful after deposits or withdrawals, whereas a fixed amount silently changes its relative severity as the balance moves.

Does the breaker need to close open positions when it fires?

It depends on the contract type: fixed-stake contracts cannot be closed early and the stake is already committed, while Multipliers can be closed, and the policy must state explicitly which behaviour is chosen before trading begins.

Can the bot re-arm itself automatically after a cool-down period?

It should not, because automatic re-arming converts a hard stop into a timed pause and removes the diagnostic step that makes recovery meaningful.

Key Takeaways

  • Drawdown is measured peak-to-trough on reported equity, with the peak persisted outside the bot’s memory.
  • The breaker must be evaluated on every balance update and re-checked immediately before any purchase call.
  • The halt flag must survive restarts; a bot that forgets it was halted has no breaker.
  • Re-arming is a documented configuration change with a fresh demo sample, not a reset button pressed after a loss.
  • A drawdown breaker complements daily loss and consecutive-loss limits; it does not replace them.

The full implementation, including configurable thresholds and persisted halt state, is available in the ORSTAC repository, which hosts open-source bots for Deriv; a free demo account is available to test the bots before any real-money use. Questions and implementation notes are welcome in the ORSTAC Telegram group.

Trading involves significant risk and you can lose your entire stake. Test every strategy on a demo account first.