Explainers / Twin Range Filter
Twin Range Filter, explained from the source
Twin Range Filter by colinmck is one of the most-boosted trend scripts on TradingView, and KivancOzbilgic's "Twin Range Filter Visualized" draws the same thing as a line. The name suggests two filters working together. The published source shows something simpler: two range measurements are averaged into one number, and that one number drives an ordinary Range Filter. The Long and Short labels come after price has turned about two ranges from its last extreme close.
The two ranges
The script measures how much price usually moves per bar, twice:
- Fast: the average absolute bar-to-bar change of the close over 27 bars, smoothed again over 53 bars (twice the period minus one), times 1.6.
- Slow: the same over 55 bars, smoothed over 109 bars, times 2.0.
It then takes the average of the two. Call that r. Both halves measure the same thing (typical bar size) with long, slow smoothing, so they rise and fall together. In our simulation they were correlated at 0.9975, and their average was matched to within about 1% by a single range of 40 bars times 1.8. The labels from that single range were the same as the twin's on 98% of bars. In practice, "twin" means one range of about 1.8 typical bar moves.
The line: a ratchet that ignores small moves
The filter is the same rule as the Range Filter:
- If the close is above the line by more than r, the line moves up to close minus r. Otherwise it stays.
- If the close is below the line by more than r, the line moves down to close plus r. Otherwise it stays.
So the line ignores any move smaller than r; in the simulation it stayed flat on about two bars in three. colinmck's version does not plot this line at all, only the labels. The Visualized version plots a stepped line built from the filter plus and minus r.
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 Long label prints on the first bar where the line steps up after its last step was down, and Short on the reverse. The two-part conditions in the code reduce to "close above the line, last step up, and the close changed".
After a rise the line sits r below the highest close, so it can only step down after a close more than r below the line: at least about 2 r below the highest close. In the simulation the median move from the extreme close to the label was 2.3 r, and the label came a median of 5 bars after that extreme.
The Visualized version labels BUY and SELL when the close crosses its stepped line instead. In our simulation 99% of those crosses landed within one bar of a colinmck label: the two scripts mark the same turns.
Twin vs the original Range Filter
The difference that matters is the width. The Range Filter scripts use multipliers of 2.618 (DonovanWall's original) or 3.0 (the "Buy and Sell 5min" version); the twin's effective multiplier is about 1.8. A narrower band waits for a smaller turn, so it labels more often and reverses more often:
| Simulation, random walk | label every | undone within 5 bars |
|---|---|---|
| Twin Range Filter (27/1.6 + 55/2.0) | 16 bars | 18% |
| Range Filter, original (14 / 2.618) | 28 bars | 5.5% |
| Range Filter Buy and Sell 5min (100 / 3.0) | 35 bars | 3.2% |
Earlier labels and more labels that reverse are the same setting seen from two sides.
Does it repaint?
On closed bars, no: the range, the line and the labels use only current and past closes, so a finished bar does not change. On the bar still forming, the close is the live price, so a label can appear mid-bar and vanish before the close. Set alerts to "once per bar close" if you only want closed-bar labels. More in what repainting is, or test a script with the repaint checker.
Settings, honestly
- Fast period / Fast range (27 / 1.6) and Slow period / Slow range (55 / 2.0): because the two ranges move together, what you are really setting is one width, roughly the average of the two multipliers, and one smoothing length somewhere between the two periods.
- To change how often it labels, change the multipliers. Raising both widens the band: fewer labels, later. Lowering both does the reverse.
- Changing only one period changes very little, because the average is dominated by what both halves share.
- There is no setting that gives earlier labels without more labels that reverse. "Best settings" depend on what you are willing to give up, and the script contains no test of any setting.
Where it fails
- The label is a trailing stop, not a forecast. It prints only after price has already come back about two ranges from its extreme close.
- It labels noise too, and often. On random-walk prices with nothing to predict it printed a label about every 16 bars, and about one in five reversed within 5 bars.
- "Twin" adds little. The two ranges are nearly the same measurement, so the script behaves like a single Range Filter with a narrower band. Stacking it with a Range Filter or the Visualized version on the same chart repeats one signal, not three.
- Slow to adapt. The ranges are smoothed over 53 and 109 bars, so after volatility changes the band stays too tight or too wide for a while.
- Open-bar labels. A label on the bar still forming can disappear before the close.
- "Long" and "Short" are names, not results. On a finished chart every label sits near a turn; live, each one came after the move it is named for.
Also explained: Range Filter · Supertrend · UT Bot Alerts · Repainting
Educational only. Not financial advice. Nothing here is a recommendation to buy or sell anything. Twin Range Filter is by colinmck, and Twin Range Filter Visualized is by KivancOzbilgic, 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, 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.