Explainers / Range Filter
Range Filter, explained from the source
"Range Filter Buy and Sell 5min" (the guikroth version of DonovanWall's Range Filter) is one of the most-boosted trend scripts on TradingView, and VuManChu Swing Free and Twin Range Filter are built on the same idea. It draws a line that steps along with price, two target bands, coloured candles and Buy/Sell labels. This page explains, from the published source, what each of those is. The short version: the line is a ratchet that ignores any move smaller than one "range", and a label appears only after price has come back at least two ranges from its last extreme close.
The range: an average bar move, smoothed and multiplied
The script first measures how much price usually moves per bar: the average of the absolute bar-to-bar change of the source (close by default) over the Sampling Period (100). It then smooths that average again over twice the period minus one (199 bars) and multiplies it by the Range Multiplier (3). Call the result r. With the defaults, r is about three times a typical bar's move, and because of the double smoothing it changes slowly.
The line: a ratchet that ignores small moves
The filter line follows one rule each bar:
- If price is above the line and more than r above it, the line jumps up to price minus r. Otherwise it stays where it is.
- If price is below the line and more than r below it, the line drops to price plus r. Otherwise it stays where it is.
So the line never moves on a small wiggle. In our simulation it stayed perfectly flat on about three bars in four. When it does move, it trails price at a distance of exactly r. The two "target" bands are simply the line plus r and the line minus r: they mark the prices a close must pass to move the line at all.
The labels: a 2 x range turn on closes
The script counts how many times in a row the line has stepped up or down. A Buy label prints on the first bar where the line steps up after it last stepped down, and a Sell label on the reverse. (The two-part conditions in the code, "price above the line and rising, or above the line and falling", reduce to "price above the line, the line's last step was up, and the close changed".)
That makes the turn point easy to compute. After a rise, the line sits r below the highest close. It can only step down when a close falls more than r below the line, which means at least 2 r below the highest close (measured with today's r; the range drifts slowly). The label is a trailing stop of two ranges on closes, with a label instead of an exit. In the simulation, the move from the last extreme close to the label was about 2 r or more in nine cases out of ten (median 2.2 r; slightly less only when the range itself had shrunk in the meantime), and the label came a median of about 10 bars after that extreme.
Does it repaint?
On closed bars, no: the line, the colours and the labels use only the current and past closes, so a finished bar does not change. On the bar that is still forming, the close is the live price, so a label can appear mid-bar and vanish before the close. An alert set to "once per bar" can fire on a label that is not on the chart afterwards; use "once per bar close" if you only want closed-bar labels. More on this in what repainting is, or test a script with the repaint checker.
"5min" settings vs the original
The guikroth version's defaults (Sampling Period 100, Multiplier 3.0) are labelled in the code as settings "for 5min chart, BTCUSDC", with a note to change them for other coins. They are not tuned for anything else, and the script contains no test of them. DonovanWall's original uses a much shorter period (14), lighter smoothing (27) and a 2.618 multiplier, and adds options: ATR, standard deviation, points, pips or % of price for the range; wicks instead of closes; a second filter type that moves in whole steps of r; and averaging of the filter's changes.
In the simulation the two defaults behaved alike: a label every 35 bars (guikroth) vs every 28 bars (original), with 3-6% undone within 5 bars. The bigger difference is speed of adapting: the 199-bar smoothing means the guikroth range takes a long time to catch up after volatility changes, so the same r can be too tight after a quiet spell turns busy, and too wide after a busy spell calms down.
Settings, honestly
- Source (close): what the filter follows.
- Sampling Period (100): how many bars the average move is taken over; the smoothing length is set from it (2 x period - 1).
- Range Multiplier (3.0): the width r in typical bar moves. The label needs a 2 r turn, so doubling the multiplier doubles the move it waits for.
- There is no setting that gives earlier labels without more labels that reverse.
The code also includes a commented-out strategy block with a fixed 400-pip target and 100-pip stop. Those numbers are an example in a comment, not tested values.
Where it fails
- The label is a trailing stop, not a forecast. It prints only after price has already come back at least two ranges from its extreme close, about 10 bars later in our simulation.
- It labels noise too. On random-walk prices with nothing to predict it still printed a label about every 28-35 bars.
- Flat line, slow range. The line ignores moves smaller than r, and r adapts slowly (199-bar smoothing at the defaults), so after a volatility change the filter is either too jumpy or too slow until the average catches up.
- Open-bar labels. A label on the bar still forming can disappear before the close; set alerts to bar close if that matters.
- "Buy" and "Sell" are names, not results. The script contains no test of what happened after its labels, and the 5min settings are the author's starting point for one coin pair.
- Back-tested labels look cleaner than they traded. On a finished chart every label sits near a turn; live, each one came after the move it is named for.
Also explained: Supertrend · Chandelier Exit · UT Bot Alerts · Repainting
Educational only. Not financial advice. Nothing here is a recommendation to buy or sell anything. Range Filter is by DonovanWall, and the Buy and Sell 5min version is by guikroth, on TradingView; this page explains their published open-source code and is not affiliated with either author.
Also explained: Repaint checker, VWAP, Supertrend, RSI, UT Bot Alerts, Nadaraya-Watson Envelope, Squeeze Momentum, What is repainting on TradingView?, Is TradingView backtesting accurate?, Chandelier Exit, WaveTrend Oscillator, QQE MOD, Pivot highs and lows, Hull Suite, Twin Range Filter, HalfTrend, ZigZag++, SSL Hybrid, CM MacD Ultimate MTF, Volume Profile / Fixed Range, ADX and DI, Support Resistance Channels, Market Structure Break & Order Block, Order Block Finder, Pivot Point SuperTrend, Trendlines with Breaks [LuxAlgo], Divergence for Many Indicators, TradingView script selling terms, Support and Resistance Levels with Break, Liquidity Swings [LuxAlgo], Pine Script errors, Breakout Probability (Expo), Did ChatGPT or Claude write your Pine Sc, Lorentzian Classification, SuperTrend AI (Clustering), Machine Learning Adaptive SuperTrend, Dynamic Swing Anchored VWAP, Support and Resistance Power Channel by , Support and Resistance (High Volume Boxe, Trendline Breakouts With Targets by Char, Breakout Finder by LonesomeTheBlue
Get the next teardown by email
One short email when a new teardown or free tool goes live, about twice a month. No signals, no hype. Unsubscribe in one click.
Almost done. Check your inbox and click the confirmation link.
Sent with Kit. Your address is used only for these emails. Privacy
No TradingView account yet? This affiliate link gives you a $15 coupon toward a paid plan, and we earn a commission if you buy one. The free plan is enough to follow this page.