Strategies & Indicators

Warm-Up and Regime Detection for Deriv Strategy Switches

· 8 min read

Regime detection is the practice of deciding, from observable data, whether the market conditions a strategy was designed for are still present. On Deriv synthetic indices and forex, the practical answer is a two-layer filter: a rolling volatility measure that flags when price dispersion changes materially, and a trend or persistence measure that flags when directional structure changes. This article shows how to compute both, how to define switch conditions with hysteresis, and how to hand off control between strategies without corrupting state or acting on the first noisy reading.

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

Layer one: rolling volatility as a regime primitive

Volatility is the cheapest regime signal to compute and the hardest to compute well. The naive approach, a rolling standard deviation of returns over a fixed window, is sensitive to the window length and to a single outlier. A more robust construction uses two windows of different length and compares them, so the signal is relative rather than absolute.

Define log returns on the mid price:

rt = ln(Pt / P_{t-1})

Then compute a short-window standard deviation, say 20 bars, and a long-window standard deviation, say 200 bars. The ratio

V = sdshort / sdlong

is dimensionless and comparable across instruments. A ratio near 1 means current dispersion resembles the recent baseline. A ratio above a threshold, for example 1.5, indicates a volatility expansion. A ratio below 0.7 indicates compression. These thresholds are illustrative; calibrate them on your own recorded sample and report how many configurations you tried, per ORSTAC’s backtesting premise.

Two practical cautions apply to synthetic indices specifically. First, Deriv’s synthetic indices are generated by a defined stochastic process, so their long-run statistical character is more stable than forex, but short-window behaviour still clusters. Second, tick frequency and bar construction differ between instruments and between DBot configurations; a 20-bar window on one-minute candles is a different economic quantity than 20 ticks. State your bar definition explicitly and keep it fixed across the backtest and the live bot.

For forex, the same ratio works but the long window must span at least a full session cycle. A 200-bar window on hourly candles covers roughly eight trading days, which is short enough to react and long enough to avoid reacting to a single news spike. If your broker feed has gaps over weekends, exclude flat bars from the return series or the standard deviation will be biased downward.

Layer two: trend and persistence filters

Volatility tells you how much price moves, not in which direction or with what persistence. A trend filter addresses that. The simplest is a normalised slope: fit a least-squares line to the last N closes and divide the slope by the average true range over the same window. The result is in units of “range per bar,” which makes it comparable across instruments.

A second useful measure is the efficiency ratio, sometimes called the fractal dimension proxy:

ER = |Pt – P{t-N}| / sum(|Pi – P{i-1}|, i from t-N+1 to t)

ER near 1 means price moved in a straight line over the window; ER near 0 means it wandered. This distinguishes a trending regime from a choppy one even when volatility is identical.

Combine the two layers into a small state table. The exact thresholds are yours to calibrate; the structure is what matters.

Volatility ratio V Efficiency ratio ER Regime label
V < 0.7 | any | Compression |
| 0.7 ≤ V ≤ 1.5 | ER 1.5
any Expansion / unstable

Each strategy you run should declare which regime labels it is allowed to operate in. A mean-reversion digit strategy, for instance, might declare “Choppy / range” only. A trend-following multiplier strategy might declare “Trending” only. Strategies that are regime-agnostic still benefit from a hard stop during “Expansion / unstable,” because that label usually coincides with the largest adverse excursions.

Worked example: a switch decision with hysteresis

Suppose a bot runs a range strategy on a synthetic index and a trend strategy on the same instrument. The range strategy is allowed when V is between 0.7 and 1.5 and ER is below 0.3. The trend strategy is allowed when V is between 0.7 and 1.5 and ER is at least 0.3. Both are suspended when V exceeds 1.5 or falls below 0.7.

Naive switching on a single reading will oscillate. If ER hovers around 0.3, the bot will flip strategies every bar, paying spread and stake on each entry. Hysteresis fixes this: require the new regime to persist for K consecutive bars before committing, and require the old regime to have been exited by a margin.

Illustrative parameters: entry threshold for trend is ER ≥ 0.35, exit threshold for trend is ER < 0.25, and persistence K = 5 bars. A reading of ER = 0.32 does nothing. A reading of ER = 0.36 for five consecutive bars switches to trend. A subsequent reading of ER = 0.27 keeps the trend strategy active; only ER < 0.25 for five consecutive bars switches back.

The cost of hysteresis is latency: you enter the new regime late. The benefit is fewer false switches. Estimate the trade-off on your recorded sample by counting how many switches occur with and without persistence, and by measuring the expectancy of each strategy in the bars immediately following a switch. If post-switch expectancy is materially worse than steady-state expectancy, your K is too small or your thresholds are too tight.

### Safe handoff logic and warm-up

The dangerous part of regime switching is not the decision; it is the handoff. A strategy that has internal state (a position, an accumulator open, a multiplier with an active stop, a pending contract) cannot be suspended mid-flight without either closing cleanly or being marked as "draining." State corruption typically arises when a new strategy starts while the old one still has an open contract, or when the new strategy's indicators are computed on a series that was not maintained during the suspension.

Two rules prevent most of this.

First, maintain all indicator series continuously, regardless of which strategy is active. The volatility and efficiency calculations should run on every bar, always. A strategy that is "off" is only off for order placement, not for data ingestion. This guarantees that when the handoff occurs, the incoming strategy has a fully warmed-up indicator state rather than a cold start.

Second, handoff is a two-phase operation. Phase one is "quiesce": stop accepting new entries from the outgoing strategy and wait for any open contract to settle or for the strategy's own exit condition to fire. Phase two is "activate": only after the outgoing strategy reports zero exposure does the incoming strategy begin placing orders. In DBot terms, this is a state variable checked at the top of the trade block, not a mid-block branch.

A minimal DBot block sequence for this:

1. On every tick or bar, update rolling volatility and efficiency series.
2. Compute V and ER; update a candidate regime label.
3. Increment or reset a persistence counter based on whether the candidate matches the current regime.
4. If persistence counter ≥ K and current strategy has zero open contracts, set current strategy to the candidate and reset the counter.
5. If current strategy has open contracts, do nothing; the handoff waits.
6. Trade block: if current strategy equals "range" and regime is "Choppy / range," evaluate range entry conditions; else if current strategy equals "trend" and regime is "Trending," evaluate trend entry conditions; else skip.
7. Apply session-level limits (daily loss, maximum drawdown, consecutive losses) before any entry, independent of regime.

Warm-up deserves its own note. The long volatility window needs at least its full length of bars before V is meaningful. If your long window is 200 bars, the first 200 bars after bot start produce an undefined or distorted V. Do not trade during warm-up. Log the warm-up period and verify in the backtest that no trades occur before the series is fully populated. The same applies after any gap in the data feed: if the bot reconnects and the series has a hole, either backfill from history or restart the warm-up, but do not splice across the gap silently.

### Limitations

This approach does not predict regime changes; it detects them after the fact, with latency set by your windows and persistence counter. It does not tell you whether a strategy has positive expectancy in a given regime; that must be established separately by backtest and demo sample. It does not handle structural breaks in the data feed, such as a change in tick generation or a symbol specification change, which can invalidate every threshold. It does not remove the need for hard session limits, and it does not make martingale-style progressions safe; ORSTAC recommends against martingale, and any progression still needs a hard cap on steps and stake plus a ruin test before live use. Finally, thresholds calibrated on one instrument do not transfer automatically to another; recalibrate per market and record how many configurations you tried.

### Frequently Asked Questions

**Can I use a single threshold instead of hysteresis?**
Yes, but a single threshold will produce more switches and more false entries near the boundary; hysteresis trades latency for stability, and the right balance depends on your strategy's holding period.

**Does regime detection work the same on synthetic indices and forex?**
The mathematics is identical, but the calibration differs because synthetic indices follow a defined stochastic process while forex reflects macroeconomic flow, so the same window lengths and thresholds will not transfer without re-testing.

**What happens if the bot disconnects mid-handoff?**
On restart, the bot should treat any unknown exposure as "quiesce" and refuse new entries until it has confirmed zero open contracts and rebuilt its indicator series, either from history or via a fresh warm-up.

### Key Takeaways

– Compute volatility as a ratio of short-window to long-window standard deviation, and trend as an efficiency ratio; both are dimensionless and comparable across instruments.
– Use hysteresis: entry and exit thresholds separated by a margin, plus a persistence counter, to avoid oscillating between strategies.
– Maintain all indicator series continuously and hand off in two phases (quiesce, then activate) to prevent state corruption.
– Enforce warm-up periods and never trade before the long window is fully populated; treat data gaps as warm-up resets.
– Calibrate thresholds per instrument, record how many configurations you tried, and keep session-level loss limits independent of regime logic.

The full set of ORSTAC bot templates, including regime-filter scaffolding you can adapt in DBot, is available in the ORSTAC repository. The bots are built for Deriv, where a free demo account is available to test them before any real stake is considered. Discussion, calibration notes and bug reports belong in the ORSTAC Telegram group. For API-level details, see the Deriv API documentation and the official Deriv API libraries; for platform mechanics, see Deriv Bot and the synthetic indices overview.

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