Most strategies are built around a particular kind of market behaviour. Trend systems need sustained moves. Mean-reversion systems need prices that stretch and snap back. Breakout systems need volatility to expand after it contracts. Each one tends to do well when its conditions are present and poorly when they aren't.
That isn't a flaw in itself. The problem is not knowing which conditions your backtest was made of. A ten-year backtest can look diversified while most of its profit came from two years that suited the strategy perfectly. Regime testing breaks the result down by market condition, so you can see what the strategy depends on before the market changes.
One point up front: regime testing describes how a strategy behaved in past conditions. It can't tell you which regime comes next, and a strategy that has done well across several regimes can still lose money in a new one.
What a "regime" means in practice
A regime is a stretch of market behaviour with a measurable character. For EA testing, three dimensions cover most needs:
- Trend: is price moving persistently in one direction, or going sideways?
- Volatility: are price ranges large or small compared with recent history?
- Session or time: for intraday systems, which trading session is active?
Keep the definitions simple. The aim is to describe conditions, not to build a second strategy.
Step 1: Define regimes before looking at results
Pick each definition and its thresholds before you split any results. Choosing thresholds after seeing which split flatters the strategy is optimization by another name.
Simple, common definitions:
- Volatility regime: the Average True Range (ATR) at entry, ranked against its own trailing history and split into low, middle and high thirds.
- Trend regime: the slope of a long moving average, or a trend-strength indicator such as ADX, split into trending and non-trending at a level fixed in advance.
- Session: the hour of entry, grouped into the main trading sessions in a fixed time zone.
Every regime label must use only information available at the time of entry. Calculating a regime from the whole day, or from a centred window, leaks the future into the label; see look-ahead bias and other code bugs that make EA backtests lie.
Step 2: Label every trade
Export the trade list and the price data, then attach the regime at each trade's entry time.
import pandas as pd
def label_regimes(bars, trades, atr_len=14, rank_window=250, ma_len=100):
"""bars: OHLC DataFrame indexed by time. trades: DataFrame with 'entry_time'
and 'r' (result in R-multiples). Labels use only data up to the prior bar."""
tr = pd.concat([bars.high - bars.low,
(bars.high - bars.close.shift()).abs(),
(bars.low - bars.close.shift()).abs()], axis=1).max(axis=1)
atr = tr.rolling(atr_len).mean()
atr_rank = atr.rolling(rank_window).rank(pct=True)
slope = bars.close.rolling(ma_len).mean().diff(20)
feats = pd.DataFrame({
"vol": pd.cut(atr_rank, [0, 1/3, 2/3, 1], labels=["low", "mid", "high"]),
"trend": (slope > 0).map({True: "up", False: "down"}),
}).shift(1) # prior bar only: no look-ahead
labels = feats.reindex(trades.entry_time, method="ffill").reset_index(drop=True)
return pd.concat([trades.reset_index(drop=True), labels], axis=1)
labelled = label_regimes(bars, trades)
summary = labelled.groupby(["vol", "trend"]).r.agg(["count", "mean", "sum"])
print(summary)
The shift(1) matters: it makes each label depend only on bars that had closed before the entry.
Step 3: Read the breakdown
Look at three things for each regime: how many trades it holds, the average result per trade, and its share of total profit.
Where does the profit come from?
If one regime produces nearly all of the profit while the others roughly break even or lose, the strategy is a specialist. That's fine if you know it, and dangerous if you assumed otherwise.
Is the breakdown consistent with the logic?
A trend system that makes money mainly in trending regimes is behaving as designed. A trend system that makes its money in ranging, low-volatility periods is behaving unexpectedly, and that deserves an explanation before you trust it. Unexplained profit is a common sign of a fitted pattern rather than a real behaviour.
Is there enough data in each cell?
Splitting trades by regime shrinks every sample. A regime cell with a handful of trades says little either way; see how many trades a backtest needs. Combine cells, or use fewer regimes, until each one has a meaningful count.
What does the backtest period contain?
Look at how much of the test history sat in each regime. If the strategy's favourite regime makes up an unusually large share of the backtest, the overall result overstates what a more mixed period would produce.
How long do unfavourable regimes last?
Average results per regime hide time. A regime that costs a little per trade can still produce a long, deep drawdown if the market stays in it for months. Mark each stretch of history by regime, then measure:
- The longest continuous run of each unfavourable regime in the test history.
- The drawdown the strategy suffered during those runs.
- How long it took to recover once the regime changed.
These numbers matter more for practical decisions than the per-trade averages. They tell you roughly how long you might need to keep running a specialist strategy through conditions it doesn't suit, and whether you could tolerate that in practice. If the longest unfavourable run in your data is short, remember that the next one could be longer; the backtest only contains the runs history happened to produce.
Do drawdowns cluster in one regime?
Check where the largest drawdowns happened. If most of the deepest drawdowns sit in one regime, that regime is the strategy's main risk, even if the average result there looks only mildly negative. That's useful for sizing and for stop rules, because a drawdown that arrives in a known hostile regime is more expected than one that arrives in conditions the strategy normally handles well.
Step 4: Connect it to walk-forward results
Walk-forward analysis shows performance over time. Regime testing shows performance by condition. Together they explain each other.
Illustrative teaching example. In our sample stress-test report, "System A-14", an anonymized, composite daily-bar trend system, showed walk-forward decay: each window's in-sample optimization kept looking strong while out-of-sample performance weakened. The report read that pattern as a sign of overfitting to recent regime characteristics rather than a durable structural edge. It also noted that trend-following systems can look strong in backtests that span a handful of large directional moves. (Illustrative example only.)
A regime breakdown is the natural next step after a result like that: label the trades in the weak out-of-sample windows and check whether those windows were dominated by conditions the strategy struggles in. The walk-forward method itself is covered in how to walk-forward test an EA.
Step 5: Decide what to do about it
A regime breakdown leaves you with three honest options.
- Accept the dependence. Trade the strategy as a specialist, size it for the losing regimes as well as the winning ones, and decide in advance how long a poor stretch you'll tolerate.
- Combine it with something different. A strategy that does well in the regimes where the first one struggles can smooth the overall result, if the two really are different.
- Add a regime filter. Only trade when the favourable regime is present.
The third option is the most tempting and the riskiest. A filter is another parameter. Choosing it after seeing the breakdown fits it to the same history you are judging it on. If you add one:
- Define it from the strategy's logic, not from the best-looking cell.
- Freeze it, then test it on data that played no part in choosing it; see out-of-sample testing for EAs.
- Check its neighbours. If a slightly different threshold removes the benefit, the filter is a spike, not a plateau; see how to spot an overfit backtest.
- Expect it to cut trade count, which weakens every other statistic.
Step 6: Watch the regime once trading
Once the EA is running, the regime labels become a monitoring tool. Track the current regime alongside results. If performance weakens while the market sits in a regime the strategy has historically struggled in, that is consistent with the test. If performance weakens in a regime that historically suited it, something else may have changed, and it is time to investigate. Monitoring is covered in the EA pre-live checklist.
Common regime-testing mistakes
- Choosing regime thresholds after seeing results.
- Labelling regimes with future data, such as the full day's range or a centred indicator.
- Splitting into too many regimes for the number of trades.
- Adding a regime filter without out-of-sample validation.
- Ignoring the regime mix of the backtest period.
- Assuming the next regime will resemble the last.
Regime-testing checklist
- Regime definitions and thresholds fixed before looking at results
- Labels use only data available before each entry
- Trades labelled by volatility, trend and, for intraday systems, session
- Trade count, average result and profit share checked for each regime
- Breakdown compared with the strategy's intended logic
- Share of backtest time in each regime checked
- Weak walk-forward windows examined by regime
- Any regime filter frozen and validated on untouched data
- Regime tracked alongside live or demo results
Frequently asked questions
What is market regime testing?
It is breaking a strategy's backtest results down by market condition, such as trending versus ranging or high versus low volatility, to see which conditions the strategy depends on.
How do I define market regimes for a backtest?
Use simple, measurable definitions fixed in advance, such as volatility ranked against its own history and trend measured by a moving-average slope. Make sure every label uses only information available before the trade's entry.
Should I add a filter so my EA only trades in good regimes?
Only with care. A regime filter chosen after seeing results is a form of optimization. Define it from the strategy's logic, freeze it, and test it on data that played no part in choosing it.
Can regime testing predict when a strategy will stop working?
No. It shows which past conditions suited the strategy. It can't forecast the next regime, and markets can behave in ways absent from the backtest.
How is regime testing different from walk-forward testing?
Walk-forward testing looks at performance across time windows. Regime testing looks at performance across market conditions. They answer different questions and are most useful together.
Want a second pair of eyes?
Start with our free Sample Stress-Test Report. It walks one anonymized, illustrative strategy through a full stress test, start to finish, so you can see what rigorous validation looks like before you test your own.
Read the Sample Stress-Test ReportWant your own backtest checked? The Strategy Audit + 60-minute call is a paid service at a launch price of £100, credited in full against our build and portfolio offers. You send an MT4/MT5 Strategy Tester report or trade-list CSV; what we can check depends on the files you supply, and walk-forward and parameter sweeps are not included because they need the strategy itself. It is analysis of strategy testing, not investment advice, and does not promise any trading or evaluation outcome. See the Strategy Audit
Disclaimers
CollosoTrading provides educational content and analytical services for retail and professional algorithmic traders. We do not provide regulated investment advice, financial advice, or personal recommendations. Trading derivatives, leveraged products, and CFDs carries a high level of risk and may result in losses exceeding deposits. Past performance, including any verified or unverified historical results referenced on this site, is not indicative of future results. Consult an independent regulated financial adviser before making investment decisions.
All figures are backtests or simulations unless marked LIVE. Hypothetical or backtested performance results have inherent limitations and may not reflect actual trading. No representation is made that any account will or is likely to achieve profits or losses similar to those shown. Individual results vary. All figures in this article come from an anonymized, illustrative teaching example. We do not guarantee the outcome of any prop firm challenge.