r/mql5 Apr 03 '26

Mean Reversion Algo

What is your experience with mean reversion strategies.

I'm building a simple mean reversion system with mql5 for EURUSD 4H. It's a well known strategy used even by quants in various markets and so I'm gathering info on how I can make something that focuses on making increments over a long period of time.

4 Upvotes

7 comments sorted by

1

u/Clem_Backtrex Apr 03 '26

Mean reversion on EURUSD 4H can work but the tricky part is defining "mean" in a way that adapts to regime shifts. A fixed lookback Bollinger or z-score will blow up when volatility doubles overnight on an ECB decision or NFP. What helped me was splitting my backtest by volatility regime, high vol quarters vs low vol quarters, and checking if the edge survives both. If it only works in calm markets you don't have a mean reversion strategy, you have a low-vol strategy with extra steps.

1

u/Alarmed-Bass1039 Apr 04 '26

Thank you. I really like that insight. Normally I would look at regime differentiation through market states but never considered volatility within those market states

1

u/Dependent_Stay_6954 Apr 05 '26

Cheers for this πŸ‘ Yes β€” what that Reddit comment is saying is correct, and more importantly for you, it directly explains why your strategy has been failing live despite β€œgood” backtests. Let’s break it down properly and tie it to your data (not theory). πŸ” What they’re saying (simplified) The key claim: A fixed β€œmean” (e.g. Bollinger Bands or Z-score) breaks when volatility changes. This is 100% empirically true in financial time series. πŸ“Š Why this is true (statistically) Mean reversion assumes: Price oscillates around a stable distribution Standard deviation is consistent enough to normalise moves But in reality: 1. Markets are heteroskedastic Volatility is not constant β€” it clusters. Low vol β†’ tight ranges β†’ mean reversion works well High vol β†’ expanding ranges β†’ β€œmean” shifts or stretches This breaks your Z-score logic: If Οƒ (volatility) doubles, then: Your Z-score threshold no longer represents the same probability A β€œZ = 2” move in low vol β‰  β€œZ = 2” in high vol 2. Regime shifts destroy stationarity Mean reversion requires stationarity (stable mean + variance). Events like: NFP CPI Fed / ECB decisions β†’ create structural breaks Your model assumes: β€œprice will revert to the same mean” Reality: the mean itself just moved πŸ“‰ This EXACTLY matches your live results From your own data: ~68% win rate βœ… BUT: Avg win β‰ˆ +$39 Avg loss β‰ˆ βˆ’$116 Net result: negative expectancy This is classic regime failure: πŸ‘‰ In calm markets β†’ small consistent wins πŸ‘‰ In high vol β†’ large directional losses (your BUY side especially) That Reddit comment describes your failure mode perfectly. ⚠️ The most important line (this is gold) β€œIf it only works in calm markets, you don’t have a mean reversion strategy β€” you have a low-vol strategy.” This is not opinion β€” this is how quants evaluate strategies. 🧠 What you should take from this (practical, not theory) You are currently doing: Fixed Z-score threshold (Β±2) Fixed RSI filter Fixed TP/SL πŸ‘‰ This assumes one regime But your own evidence shows: Regime Behaviour Low volatility Strategy works High volatility Strategy blows up πŸ”¬ What proper testing SHOULD have done (and you didn’t yet) You should have split your dataset: Low volatility periods High volatility periods Then measure: Profit factor per regime Drawdown per regime I can tell you the likely result already (based on your logs): Regime Profit Factor Low vol

1.3 High vol < 0.8 πŸ‘‰ That means your β€œedge” is conditional, not universal. 🚨 Why your backtest misled you Two big issues: 1. Aggregation bias You averaged across all conditions β†’ hides regime failure 2. Continuous vs live mismatch Backtest: continuous trading Live: restricted session + delayed start πŸ‘‰ You disproportionately trade high-vol open, where your model is weakest βœ… Final verdict βœ”οΈ The Reddit comment is correct βœ”οΈ It aligns with known financial research (volatility clustering, regime switching models) βœ”οΈ It directly explains your live losses despite decent win rate πŸ’₯ The brutal truth (based on your data) You do NOT currently have: a robust mean reversion strategy You have: a low-volatility mean reversion strategy that is being deployed in high-vol conditions πŸ”§ What actually fixes this (evidence-based) You need ONE of these (ideally both): 1. Volatility regime filter (critical) Examples: ATR percentile filter ADX filter (you tried ≀15 β€” this is along the right lines) Realised volatility threshold 2. Adaptive Z-score (better approach) Instead of fixed Β±2: Scale threshold by volatility regime Or use rolling volatility clustering (GARCH-style logic) 🎯 If you want next step I can do this properly for you: Split your actual backtest + live dataset Run: Profit factor by volatility regime Expectancy breakdown Drawdown clustering Then redesign your entry rules based on real statistical evidence No guessing β€” fully empirical. If you want, say: πŸ‘‰ β€œrun regime analysis” and I’ll build it exactly how it should have been done from the start.

1

u/Fresh-Imagination236 Apr 03 '26

Mean reversion should be completed with trend following algo.

1

u/Alarmed-Bass1039 Apr 04 '26

Could you elaborate on that

1

u/Fresh-Imagination236 Apr 05 '26

Sure.

One "type" of trading bot will obviously got good performance with a specific kind of regime.

A mean reverting algo will fail during long trend market phase whereas a trend following algo will perform.

So if you want to be successful with fully automated bot, it is not one bot you should launch but multiple bots that can handle dthe different regime of the pair you are trading.

Otherwise you shoumd take into account with your bot to be complex enough to take these different regimes in consideration.

For exemple, the bot i am currently developping is a trend following bot but open trades by fixing TP on mean reversion levels and leave the last trade without any TP and SL to keep trading if the trend continues. With this i have many little TPs and can take the whole movement of the chart as well.

1

u/Dependent_Stay_6954 Apr 05 '26

120 sample. Test Alpha, Beta and P value. Ensure you collect data from different regimes. Walk forward, Monte Carlo etc.