Z-Score Mean Reversion with a Reusable MQL5 Engine
Summary
The article builds a reusable Z-score calculation class for an MQL5 indicator and Expert Advisor. The score measures a closing price’s distance from a rolling simple moving average in units of the rolling standard deviation over the same lookback. Its example strategy treats readings beyond symmetric positive and negative thresholds as potential short and long signals, uses closed bars for decisions, and exits when the score returns to zero. The same class is intended to support chart inspection and automated execution.
The implementation uses a fixed window and population standard deviation, and handles missing history or zero volatility by returning a neutral value. The article outlines example testing on hourly EURUSD data, but the provided material does not give specific performance figures. The author cautions that trends can extend deviations and cause drawdowns, and that the example’s fixed lot size is unsuitable as a complete risk-sizing approach. Z-scores measure unusual movement relative to recent history; they do not guarantee reversal, especially around news or macroeconomic shifts.
Key ideas
- A Z-score expresses price deviation from its rolling mean in standard deviation units.
- The example enters on closed-bar readings beyond positive or negative thresholds and exits at zero.
- A shared calculation class lets an indicator and Expert Advisor use the same normalization logic.
- The implementation handles incomplete history and zero standard deviation with a neutral reading.
- Persistent trends can extend extreme readings, so the signal is not a guaranteed reversal predictor.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.