Blog / Strategy
Strategy

Regression Residual Reversion

Disclaimer: This article is for educational and informational purposes only. It does not constitute financial or investment advice. Trading forex and CFDs carries significant risk of loss. Past performance of any strategy — including backtests — does not guarantee future results. Never trade with money you cannot afford to lose.

What Is This Strategy?

The Regression Residual Reversion strategy is a mean-reversion trading system built around linear regression — a statistical technique that fits a straight "best-fit" line through recent price closes. Rather than measuring how far price has stretched from a flat moving average, this Expert Advisor (EA) fits a sloped trend line through the last several bars and then measures how far the most recent bar sits from that line. It is designed as a study in disciplined, counter-trend "fade the outlier" trading on liquid instruments.

Most simple mean-reversion systems compare price to a horizontal reference such as a moving average. The problem with that approach is drift: in a gently rising or falling market, a bar can look "far from the average" simply because the average is lagging behind, not because price has genuinely over-extended. Regression Residual Reversion addresses this by regressing price on time. The fitted line becomes the market's current expectation of price given its recent drift, and the distance of each bar from that line — the residual — becomes a cleaner statistical measure of how stretched price really is.

This strategy is best suited to traders who want to learn how statistical concepts like least-squares regression, standard error, and standardized scores (z-scores) can be translated into concrete entry and exit rules. It is an intraday, single-timeframe approach designed with liquid forex majors such as EUR/USD in mind. It is an analytical learning tool, not a shortcut — the value here is understanding why each filter exists.

How It Works

The strategy processes signals only when a new bar closes, so it works on completed data rather than a flickering, still-forming candle. Here is what happens on each closed bar:

The entry rules read as follows:

Stop-loss and take-profit logic:

Trade management: once a position is open, the stop moves to breakeven after price travels BreakevenAtr × ATR in favour, then trails by TrailAtr × ATR behind price. This is intended to keep a winner from round-tripping back into a loss. Only one position per magic number is held at a time.

regression residual reversion MT5 EA
Illustrative example of the strategy’s entry and exit logic — not real trading results.

Strategy Parameters

Parameter Default Min Max Description
RegPeriod 40 15 120 Number of closes fitted for the regression line and residual scale (the lookback window).
EntryZ 2.2 1.5 3.5 Outlier threshold in regression-standard-errors; how far a bar must stretch to qualify.
FlatSlopeMax 0.60 0.20 1.50 Maximum slope /ATR that still counts as "flat" enough to fade (the trend filter).
AtrPeriod 14 7 30 Period of the ATR used for the stop scale and trade management.
StopAtrMult 1.0 0.5 3.0 Structural-stop buffer, in ATRs, placed beyond the excursion extreme.
MaxRiskAtr 2.5 1.0 5.0 Rejects setups whose implied stop is wider than this many ATRs (risk cap).
MinTargetAtr 0.5 0.1 3.0 Requires the fair-value target to be at least this many ATRs away.
BreakevenAtr 0.8 0.3 3.0 Moves the stop to breakeven once price advances this many ATRs in favour.
TrailAtr 1.2 0.5 4.0 After breakeven, trails the stop this many ATRs behind price.
Lots 0.10 0.01 1.0 Trade volume in lots.
regression residual reversion MT5 EA — MQL5 source code

Recommended Chart Settings

Regression Residual Reversion was designed with liquid forex majors such as EUR/USD in mind, on intraday timeframes (for example M15 to H1). Because every price read uses the chart's own timeframe, you can attach it to whichever timeframe you are studying, and the ATR-based stops and self-scaling standard error will adapt to that timeframe's volatility.

Keep in mind that mean-reversion behaviour differs enormously across symbols and sessions. A setting that looks reasonable on EUR/USD during quiet European hours may behave very differently on a volatile pair or during major news. Results will vary across different market conditions, and any timeframe or symbol change should be studied carefully on historical data before further testing.

How to Install on MetaTrader 5

What to Consider Before Using This EA

Strengths of this approach. The regression-based reference is genuinely more principled than a flat moving average when a market is drifting, because it separates trend from over-extension. The self-scaling standard error means the "how far is far?" threshold adapts to volatility automatically rather than relying on a fixed pip distance. The flat-slope regime gate is a thoughtful attempt to keep the system from fading strong trends — the single most common way mean-reversion books get hurt. And the reclaim trigger adds evidence that reversion has started before any order goes out.

Known limitations. Mean-reversion strategies, by construction, take many small wins and occasionally suffer larger losses when a supposed outlier turns out to be the start of a real move. No filter is perfect: the flat-slope gate can still be caught out when a range breaks into a trend right after an entry. The take-profit at the regression line is a modest target, which historically pairs small average wins with a stop that must be respected strictly — the reward-to-risk profile depends heavily on the parameter choices.

Where it may underperform. Strong, sustained trends and high-impact news events are the natural enemies of any fade strategy. During a fast directional move, price can remain an "outlier" for many bars, and a reclaim that looks like reversion may only be a pause. The strategy may also produce few signals in very quiet markets where nothing stretches far enough to trigger EntryZ. Treat it as one lens for studying market behaviour, not a complete system.

Risk Management Tips

Sound risk management matters more than any single strategy setting. Consider these general principles as you study this EA:

Risk Warning

Trading foreign exchange, CFDs, and other leveraged financial instruments involves substantial risk of loss and is not suitable for all investors. The strategies and tools discussed on this page are provided for educational purposes only and do not constitute financial advice, investment recommendations, or solicitation to trade. Always consult a qualified financial adviser before making trading decisions. Past backtest performance is not indicative of future results.

Downloads

← Back to Blog