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 Volume Weighted Median Reversion strategy is a mean-reversion system built around a robust fair-value anchor: the volume-weighted median of price over a rolling window of recent bars. Mean reversion is the idea that when price stretches unusually far from a central "fair" level, it tends to snap back toward that level. Instead of using a simple moving average or a VWAP (volume-weighted average price) as its reference, this strategy uses the volume-weighted median — the price level at which half of the traded volume sits above and half below. That distinction is the whole point of the design.
Why the median rather than the mean? A VWAP is an average, so a single climactic bar with enormous range and volume can drag the "fair value" toward an extreme exactly when you most want a stable reference. The median is naturally resistant to that: one outlier bar barely moves the level at which volume is balanced. Weighting the median by tick volume (rather than taking a plain price median) turns it into a liquidity-anchored equilibrium — a genuine volume balance point rather than a purely geometric midpoint. The strategy then measures how far price has stretched from this anchor using the Average True Range (ATR), a standard volatility gauge, so its over-extension threshold self-scales to current market conditions.
As a learning tool, this strategy is well suited to traders who want to study range-trading and volume-based fair-value concepts. It is designed for balanced, ranging markets, not trends, and it includes an explicit regime filter that stands aside during directional runs. If you are interested in how robust statistics (medians), volume weighting, and volatility normalization can be combined into a single disciplined rule set, this is an instructive example to examine on a demo account.
How It Works
The strategy evaluates its logic once per newly closed bar and only ever holds one position at a time. When flat, it looks for three conditions to line up before it acts.
- Build the fair-value anchor. Over the last
MedianPeriodclosed bars, the strategy computes each bar's typical price(High + Low + Close) / 3, weights it by that bar's tick volume, and finds the volume-weighted median (the VWM) — the typical-price level where cumulative sorted volume first reaches half the window's total. - Measure the stretch. The strategy checks how far the just-closed bar closed from the VWM. It signals an over-extension only when the distance is at least
StretchAtrMult × ATR. Because the threshold is expressed in ATR units, it tightens in quiet markets and widens in volatile ones. - Confirm a flat regime. The strategy compares the current VWM to the VWM
RegimeLookbackbars ago. If the anchor itself has drifted less thanFlatRegimeMult × ATR, the market is considered balanced and eligible for fading. If the anchor is steeply sloped — a trend — the setup is rejected. This gate is what keeps the system out of trend runs, where fading is typically punished. - Require a snap-back. The over-stretched bar must already show the first tick of reversion. For a long, the stretched bar must be bullish (close above open) while sitting below the VWM; for a short, it must be bearish while sitting above the VWM. This helps the strategy avoid catching a falling knife.
- Long entry. When the close is below
VWM − StretchAtrMult × ATR, the regime is flat, and the bar is bullish, the strategy signals a buy. The take-profit is the VWM itself (the balance point acts as a magnet), and the stop-loss isAtrStopMult × ATRbelow entry. - Short entry. When the close is above
VWM + StretchAtrMult × ATR, the regime is flat, and the bar is bearish, the strategy signals a sell. The take-profit is again the VWM, and the stop isAtrStopMult × ATRabove entry. - Reward-to-risk filter. Before any order is sent, the strategy compares the distance to the VWM target against the ATR stop distance. If the reward-to-risk ratio is below
MinRewardRisk, the setup is skipped because price is already too close to fair value to justify the risk. - Spread filter. If the current spread (in points) exceeds
MaxSpreadPoints, no new entry is taken, which helps avoid trading in poor liquidity conditions. - Exits. There is no separate trailing logic. Every trade is managed entirely by its ATR-based stop-loss and its VWM take-profit target, and only one position per magic number is allowed at a time.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| MedianPeriod | 40 | 10 | 150 | Rolling window (bars) used to compute the volume-weighted median fair value. |
| StretchAtrMult | 1.8 | 0.5 | 5.0 | Over-extension required: the bar must close at least this × ATR away from the VWM. |
| RegimeLookback | 20 | 5 | 80 | Number of bars back over which the VWM's own drift is measured for the regime gate. |
| FlatRegimeMult | 1.5 | 0.2 | 5.0 | Fade only when the VWM has drifted less than this × ATR over RegimeLookback bars (flat anchor). |
| AtrPeriod | 14 | 5 | 40 | Lookback length for the ATR volatility calculation. |
| AtrStopMult | 1.6 | 0.5 | 5.0 | Stop-loss distance, expressed as this × ATR beyond the entry. |
| MinRewardRisk | 0.7 | 0.2 | 3.0 | Minimum reward-to-risk ratio; setups closer than this to fair value are rejected. |
| MaxSpreadPoints | 80 | 5 | 400 | Skip new entries when the current spread (points) is wider than this. |
| Lots | 0.10 | 0.01 | 1.0 | Order volume in lots. |
| Magic | 8123 | 0 | 9,999,999 | Magic number used to identify and manage this EA's positions. |

Recommended Chart Settings
This strategy runs on a single timeframe — whatever chart you attach it to — because every calculation uses the primary symbol and period. Its natural home is a liquid FX major or a major index on the M5 to H1 timeframes, where volume-balance reversion tends to be most pronounced and tick-volume data is meaningful. Balanced, range-bound sessions suit the logic best; strongly trending or news-driven conditions are exactly what the flat-regime gate is designed to sit out. Remember that results will vary considerably across different symbols, sessions, and market conditions, so treat any chosen setting as a starting point for your own testing rather than a fixed recommendation.
How to Install on MetaTrader 5
- Download the .ex5 file from the link below
- Copy it to your MT5
MQL5\Expertsfolder - Restart MetaTrader 5 or refresh the Navigator panel
- Drag the EA onto a chart matching the recommended symbol and timeframe
- Configure the input parameters and enable Algo Trading
What to Consider Before Using This EA
The main strength of this approach is the robustness of its fair-value anchor. By using a volume-weighted median rather than an average, the reference level is far less sensitive to single climactic bars — a common weakness of VWAP-based fades. The explicit regime filter and the snap-back confirmation add discipline that many naive mean-reversion systems lack, and the ATR-scaled thresholds keep the logic consistent across changing volatility.
That said, every mean-reversion method shares a structural limitation: it is designed to fade extremes, so it can perform poorly when a market stops ranging and begins to trend strongly. The flat-regime gate reduces but does not eliminate this risk, because a market can transition from balanced to trending faster than the lookback can detect. Because the take-profit is fixed at the VWM and the stop is a multiple of ATR, individual losing trades can be larger than individual winners if the reward-to-risk filter is set loosely. The strategy also depends on tick-volume data, which is a proxy for real traded volume in decentralized forex and may behave differently across brokers. Finally, it takes only one position at a time, so it may sit idle for long stretches while waiting for its three conditions to align. Study these trade-offs on historical data and a demo account before drawing any conclusions.
Risk Management Tips
Sound risk management matters more than any single indicator setting. Consider the following general principles as you study this strategy:
- Size positions conservatively. A widely cited guideline is to risk no more than 1–2% of account equity on any single trade. Adjust the
Lotsvalue to fit your account size and the ATR-based stop distance, not the other way around. - Test on a demo account first. Run the EA in a risk-free simulated environment until you understand how it behaves across trending, ranging, and volatile conditions.
- Understand drawdown. Even a well-designed strategy will experience losing streaks. Know the maximum historical drawdown you are willing to tolerate and stop if it is exceeded.
- Mind the spread and session. The spread filter helps, but you should still avoid periods of thin liquidity and major news releases where reversion assumptions break down.
- Keep records and review. Journaling your test results helps you separate genuine edge from randomness.
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
- Expert Advisor: VolumeWeightedMedianReversion.ex5 (35 downloads)
- Source Code: VolumeWeightedMedianReversion.mq5 (33 downloads)
- Documentation: VolumeWeightedMedianReversion.pdf (44 downloads)