Blog / Strategy
Strategy

Median Line Fork 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 Median Line Fork Reversion strategy is a mean-reversion system built on Alan Andrews' median-line geometry — the technique many traders know as the "Andrews pitchfork." Instead of the flat, horizontal boundaries of a Donchian channel or the statistical fit of a linear regression channel, this approach constructs a sloped price channel directly from three recent swing pivots and then fades price whenever it stretches to one of the channel's outer rails, aiming for a return to the centre line. In plain terms, it is a counter-trend, "buy-the-dip / sell-the-rip" style tool that works within a diagonal envelope rather than a flat one.

The pivots themselves are located with a ZigZag fractal filter — a bar only qualifies as a swing high or swing low if it is the strict extreme of the small window of bars around it. Those alternating high/low pivots feed the pitchfork math. The core idea the strategy leans on is Andrews' well-known "80% rule" observation: once price reacts away from a well-formed median line, it historically tends to travel back toward that line the majority of the time. The system is therefore designed for markets that oscillate, drift, and retrace within a channel — ranging or gently trending conditions — rather than fast, one-directional breakouts.

As a learning tool, this strategy is well suited to traders who want to understand how geometric channel construction, swing-pivot detection, and volatility-based risk sizing fit together in a single automated framework. It is not a signal to chase profits; it is a structured example of how a classic charting method can be translated into precise, rule-based code. Treat it as a study in mechanical mean reversion.

How It Works

The Expert Advisor (EA) rebuilds its pitchfork continuously as new pivots confirm, then checks for fade opportunities once per completed bar. Here is the logic in plain English:

Andrews pitchfork mean reversion EA
Illustrative example of the strategy’s entry and exit logic — not real trading results.

Strategy Parameters

Parameter Default Min Max Description
PivotLookback 3 2 8 Fractal half-width for swing-pivot detection — the number of bars on each side a candidate must exceed to confirm as a pivot. Larger values find fewer, more significant swings.
AtrPeriod 14 7 30 The ATR length used both for the protective stop distance and for the minimum-room filter. Longer periods smooth the volatility estimate.
AtrStopMult 1.5 0.5 4.0 Multiplier that sets the protective stop at entry ∓ (AtrStopMult × ATR). Higher values give the trade more breathing room but risk more per position.
MaxForkAge 120 20 400 The maximum age (in bars) of the newest pivot. Forks older than this are treated as stale and skipped.
Lots 0.10 0.01 1.0 The fixed order volume (position size) used for each trade.
Andrews pitchfork mean reversion EA — MQL5 source code

Recommended Chart Settings

This strategy is single-timeframe by design — every calculation uses the chart's chosen timeframe, so you decide the timeframe when you attach it. As a starting point for study, mid-range intraday timeframes such as H1 (1-hour) on liquid major FX pairs like EUR/USD give the pivot detection enough clean swings to build meaningful pitchforks without excessive noise. Higher timeframes such as H4 tend to produce fewer but more structurally significant forks.

Because the median-line method depends on well-formed swing structure, the strategy generally behaves best in markets that oscillate within a channel. Keep in mind that results will vary considerably across different symbols, timeframes, and market conditions — always test any configuration on your own data before drawing conclusions.

How to Install on MetaTrader 5

What to Consider Before Using This EA

Strengths of the approach. The median-line method is one of the oldest and most respected pieces of technical geometry, and turning it into a rules-based EA removes the subjectivity of hand-drawing pitchforks. The sloped channel adapts to trend direction, the ATR-based stop keeps risk proportional to volatility, and the minimum-room and staleness filters help avoid the lowest-quality setups. As a study in disciplined, symmetric (long and short) mean reversion, it is a clean example.

Known limitations. Mean-reversion systems face a structural challenge: they lean against momentum. In a strong, sustained trend, price can ride an outer tine for a long time, and fading it repeatedly may lead to a series of stop-outs before the channel finally breaks. The pitchfork is also only as good as the pivots it is built from — during choppy, structureless phases the ZigZag can produce forks that describe the past better than the future. The staleness guard mitigates this but cannot eliminate it.

Where it may underperform. Expect weaker behaviour during breakouts, news-driven volatility spikes, and low-liquidity sessions where spreads widen and swing structure becomes erratic. The strategy is designed for orderly oscillation, not for regime shifts. Treat every configuration as a hypothesis to be tested, not a finished product.

Risk Management Tips

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

Automated does not mean unattended — monitor the EA, keep records, and review its behaviour regularly.

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