Blog / Strategy
Strategy

Tukey Fence 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 Tukey Fence Reversion strategy is a mean-reversion (fade) system built on one of statistics' most durable ideas: the Tukey fence, the same "boxplot" outlier test that statisticians use to flag unusual values in a dataset. Instead of applying it to survey data, this Expert Advisor (EA) applies it to the most recent closing prices, treating them as a distribution and asking a simple question — is the latest bar a genuine statistical outlier, or just ordinary noise? When a bar pierces the fence and then price snaps back, the strategy reads that as an over-extension and fades it back toward fair value.

At the heart of the method are robust statistics: the first quartile (Q1, the 25th percentile), the median (50th percentile), the third quartile (Q3, the 75th percentile), and the inter-quartile range (IQR = Q3 − Q1). Unlike a simple average and standard deviation — which a couple of violent spike bars can badly distort — quartiles barely move when a few extreme values appear. That robustness is the whole point: a bar that clears the fence is a real over-extension relative to the body of recent trade, not merely a wobble in a noisy average. Price often reverts from such an extreme back toward the median, which the strategy treats as the local "fair value."

This EA is best understood as a learning tool for traders who want to study how classical statistics can be translated into trading rules, and how a disciplined reversion system tries to avoid the classic failure mode of fading a runaway trend. It is designed for balanced, ranging market conditions — not breakouts or strong trends — and it will appeal to those curious about quartile-based over-extension detection, robust outlier logic, and Average True Range (ATR)-based risk sizing.

How It Works

The strategy processes only fully closed bars (no repainting) and evaluates two recent candles: the outlier bar (the bar before last) and the reclaim bar (the just-closed bar). It also computes an ATR — a volatility measure of the average bar range — to size stops and to gauge whether the market is flat.

Setup construction (every closed bar):

The strategy signals a long (buy) when all of the following align:

The strategy signals a short (sell) under the mirror-image conditions:

Waiting for the reclaim bar is deliberate — rather than "catching a falling knife" by buying while price is still plunging, the strategy waits for evidence that price has already turned back inside the fence.

Exit and risk logic:

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

Strategy Parameters

Parameter Default Min Max Description
Window 40 20 100 Number of recent closes forming the distribution the quartiles are measured on.
FenceMult 1.50 0.50 3.00 Tukey fence multiplier of the IQR (1.5 = classic "outlier," 3.0 = "far out"). Higher values require a more extreme move before a fade triggers.
AtrPeriod 14 7 28 ATR window used for stop/target sizing and the flat-regime gate.
FlatSlopeFrac 0.30 0.05 1.50 Flat-regime gate: the median's move per bar must be no more than this fraction of ATR for a fade to be allowed.
SlAtrMult 1.20 0.50 4.00 Stop-loss distance placed beyond the outlier extreme, measured in ATRs.
TpAtrMult 1.80 0.50 6.00 Take-profit distance back toward fair value (the median), measured in ATRs.
BreakevenAtr 0.80 0.00 3.00 Move the stop to break-even once price has travelled this many ATRs in favour (0 disables it).
Lots 0.10 0.01 1.00 Fixed trade size in lots.
Tukey fence reversion MT5 EA — MQL5 source code

Recommended Chart Settings

The Tukey Fence Reversion EA is single-timeframe: every calculation uses the chart's selected period, so the strategy simply runs on whatever timeframe you attach it to. Because it is a mean-reversion system that depends on balanced, ranging conditions, it is generally studied on liquid instruments — major forex pairs such as EUR/USD or GBP/USD — where quartile-based fair value is meaningful and spreads are tight. Intraday timeframes such as M15 to H1 are a sensible starting point for study, giving enough closed bars to populate the distribution while keeping trade frequency reasonable.

As with any strategy, results will vary considerably across symbols, timeframes, brokers, and market regimes. Treat the defaults as a baseline for experimentation on a demo account rather than a fixed recommendation. Consider testing the flat-regime gate and fence multiplier carefully, since together they control how often the strategy engages.

How to Install on MetaTrader 5

What to Consider Before Using This EA

Strengths of the approach. The use of robust statistics is genuinely thoughtful: quartiles and the IQR resist distortion from the very spike bars the strategy is trying to detect, so its fences do not "chase" the outliers that inflate a standard-deviation band. The flat-regime gate directly addresses the most common way a fade book fails — being run over while fading a trend — by refusing to trade unless the median is nearly horizontal. Waiting for a reclaim bar, anchoring the stop to the outlier extreme, and moving quickly to break-even are all disciplined risk-control choices.

Known limitations. Mean reversion, by definition, assumes price will return toward fair value — but markets can and do trend, gap, and break out. No flat-regime filter is perfect; a strong move can begin the moment after a fade is placed. Because the strategy fires only on genuine outliers, it is by design low-frequency, which means fewer trades and longer stretches with no activity — something that can test a trader's patience and makes robust evaluation require a large sample. The single-position rule caps risk but also means missed setups while a trade is open. Performance is also sensitive to spread and execution quality, since reversion edges are typically small.

Where it may underperform. Strong trending markets, high-impact news, and volatility regime shifts are the natural enemies of any fade system. In such conditions the flat gate should keep it flat, but false "flat" readings or sudden regime changes can still produce losing fades. Study it accordingly.

Risk Management Tips

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