Blog / Strategy
Strategy

Range Filter Trend Shift

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 Range Filter Trend Shift is a trend-following expert advisor built around a Range Filter, a volatility-adaptive "ratcheting" baseline that is mechanically different from the more familiar ATR channels, moving-average rails, Chandelier stops, or SuperTrend lines. Rather than gauging volatility from each candle's high-to-low range, the Range Filter measures how far price actually travels from one close to the next, and then only allows its baseline to advance once price has pushed beyond that typical travelled distance. The result is a line that absorbs small back-and-forth noise but gets dragged along by genuine directional thrust.

Because the filter line can only move in the direction of the prevailing push — it "ratchets" and never retraces against itself — its slope becomes a clean, low-noise definition of the current market regime. When the line is rising and price sits above it, the strategy treats the market as being in an uptrend; when the line is falling and price sits below it, it treats the market as being in a downtrend. Every trade is a reaction to that regime flipping from one state to the other, which is why the strategy carries the name "Trend Shift."

This EA is best understood as a learning tool for traders who want to study adaptive baselines, regime detection, and stop-and-reverse logic. It is designed for markets that produce sustained directional moves — trending forex majors or metals such as EURUSD or XAUUSD on intraday-to-swing timeframes — and it is deliberately transparent so you can inspect exactly how each signal is generated. It is not a shortcut and it is not a promise of any particular outcome; it is a framework for understanding how a travelled-distance filter behaves in different market conditions.

How It Works

The strategy processes only closed bars on the primary timeframe and rebuilds its Range Filter state machine each time a new bar closes. Here is what happens under the hood and how signals are produced:

Entry — on a fresh regime flip (stop-and-reverse):

Stop-loss and take-profit — ATR-based:

Because the filter is recomputed over a fixed window of already-closed bars and the flip is detected by comparing the last closed bar's regime with the bar before it, the signal is non-repainting — it does not change after the fact.

range filter MT5 EA
Illustrative example of the strategy’s entry and exit logic — not real trading results.

Strategy Parameters

Parameter Default Min Max Description
RangePeriod 14 5 60 Sampling length for the average close-to-close travel — the adaptive range. Shorter reacts faster; longer is smoother.
RangeMult 2.5 1.0 6.0 Scales the smoothed range. Larger values create a wider filter with fewer, slower regime flips.
AtrPeriod 14 5 50 ATR lookback used to size the volatility-scaled stop and target.
StopAtrMult 1.5 0.5 5.0 Stop-loss distance as a multiple of ATR.
TargetAtrMult 3.0 0.5 8.0 Take-profit distance as a multiple of ATR — a wide reward that aims to let trend winners run.
Lots 0.10 0.01 1.00 Fixed order volume (position size) in lots.
Magic 7311 0 9,999,999 Unique identifier so the EA only manages its own trades.
range filter MT5 EA — MQL5 source code

Recommended Chart Settings

The Range Filter Trend Shift was designed with trending FX majors or metals in mind — EURUSD or XAUUSD are the reference instruments — on H1 or H4 timeframes, where directional moves tend to persist long enough for the ratcheting line to develop a clear slope. That said, the logic is timeframe-agnostic and runs on whatever timeframe you attach it to at backtest or live time.

Keep in mind that a stepped, regime-based filter behaves very differently across market conditions. The same settings that produce clean signals in a trending environment can generate repeated flips in a choppy, range-bound market. Always study how the parameters behave on your chosen symbol and timeframe before drawing any conclusions, and expect results to vary as conditions change.

How to Install on MetaTrader 5

What to Consider Before Using This EA

Strengths of the approach. The Range Filter's travelled-distance construction gives it a genuinely different noise profile from range-based tools. By absorbing small close-to-close wobble and only stepping on real thrust, it can stay flat through minor chop and then lock onto sustained moves. The ratcheting, non-retracing line makes the regime definition unambiguous, and the stop-and-reverse design keeps the position continuously aligned with that regime rather than sitting flat and missing continuation.

Known limitations. Every stepped filter faces the same core trade-off: the very smoothing that suppresses noise also introduces lag. In a fast reversal, the line may flip late, giving back part of a move before the regime updates. And like all trend-following logic, it is structurally vulnerable to range-bound markets, where the price oscillates around the baseline and produces a series of flips that are stopped out — the classic "whipsaw" pattern. The wide ATR-multiple target helps the winners compensate, but there is no configuration that removes this behaviour entirely.

Where it may underperform. Quiet, sideways consolidations, low-volatility sessions, and news-driven spikes that immediately reverse are the conditions most likely to challenge this design. It historically favours instruments and timeframes that produce clean, extended directional legs. Treat the defaults as a starting point for study, not as an optimised or recommended configuration, and observe its behaviour across many different market phases.

Risk Management Tips

Sound risk management matters more than any single indicator setting. As general educational principles:

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