OPEN-SOURCE SCRIPT

Range Filter Trend [QuantAlgo]

5 019
🟢 Overview

The Range Filter Trend indicator tracks the direction of price through a step filter that only moves when price travels beyond an adaptive noise range. For each bar it measures the absolute bar-to-bar movement of the source, smooths that movement in two passes with a selectable moving average, scales it by a multiplier, and holds the filter flat until the source pushes beyond that range from the filter's previous value. Every step of the filter confirms the trend direction, range bands frame the zone price must break, an optional neutral state grays out extended flat stretches, and trend change markers with state based coloring make direction readable at a glance across any timeframe and instrument.
snapshot
🟢 How It Works

The indicator is built around a stepped range filter: the filter value carries forward unchanged until the source closes beyond one range width from it, then jumps to the source minus or plus the range. It has three stages: range construction from smoothed bar-to-bar movement, the step rule that produces the filter and its bands, and a state engine that reads trend direction from the filter's steps.

First, the range is built. The absolute change of the source from one bar to the next is averaged over the sampling period and then smoothed again over roughly twice that length, so a single wide bar cannot swing the range on its own. The smoothing type is selectable, and every average is computed on every bar before the chosen one is applied, keeping the internal history of each moving average consistent:
Pine Script®

Next, the step rule produces the filter. When the source sits above the previous filter value, the filter rises only if the source minus the range clears that previous value, and it rises to exactly the source minus the range. The mirror rule applies below. Otherwise the filter holds flat. The range bands sit one range above and below the filter and mark the exact levels the next close must exceed for the filter to move:
Pine Script®

Finally, the state engine reads direction from the steps. An upward step confirms a bullish trend and a downward step confirms a bearish trend, each held until the filter steps the opposite way. With the neutral state enabled, a trend releases to neutral once the filter has stayed flat for the Range Bars count, and the next step of the filter confirms a fresh trend. States update on confirmed bars, so a confirmed trend change stays in place once the bar closes:
Pine Script®

snapshot
🟢 Signal Interpretation

▶ Bullish Trend (Upward Filter Step with Bullish Color): When the filter steps up, the line, bands, and fill switch to the bullish color, reading as buyers pushing price beyond the noise range. Treat this as a long bias: strongest on the marker bar itself, or on pullbacks that hold inside the band without dragging the filter down. Bias ends when price closes below the lower band, which steps the filter down and flips the state.

▶ Bearish Trend (Downward Filter Step with Bearish Color): When the filter steps down, the line, bands, and fill switch to the bearish color, reading as sellers driving price through the noise range. Treat this as a short bias: strongest on the marker bar itself, or on bounces that fail inside the band without lifting the filter. Bias ends when price closes above the upper band, which steps the filter up and flips the state.

▶ Neutral State (Optional, Flat Filter in Neutral Color): With Use Neutral State enabled, a trend that goes quiet releases to the neutral color once the filter has held flat for the Range Bars count. This separates ranging stretches from active trends: price is oscillating inside the band without the strength to move the filter. The next step in either direction confirms a fresh trend and prints a new marker.
snapshot
🟢 Features

▶ Preconfigured Presets: Three parameter sets tuned for different trading styles and timeframes. "Default" delivers balanced trend tracking for swing trading on 1H to daily charts, with the sampling period, range multiplier, and range bars adjustable directly. "Fast Response" is built for intraday work on 5 minute to 1H charts, shortening the sampling period and narrowing the range so the filter follows price more closely and trend changes confirm sooner. "Smooth Trend" is aimed at position style reading on daily charts, lengthening the sampling period and widening the range so the filter rides through larger swings and changes state less often.
snapshot
▶ Built-in Alerts: Four alert conditions support hands off monitoring. "Bullish Trend Signal" fires on the bar an upward step confirms a bullish trend. "Bearish Trend Signal" fires on the bar a downward step confirms a bearish trend. "Neutral State" fires when an active trend releases to neutral. "Any Trend Change" fires on any state change. Alert messages include exchange, ticker, and timeframe for immediate context.
snapshot
▶ Visual Customization: Six color presets (Classic, Aqua, Cosmic, Cyber, Neon, and Custom) apply coordinated bullish, bearish, and neutral colors to the filter line, range bands, band fill, markers, optional bar coloring, and optional background coloring. Custom unlocks independent bullish, bearish, and neutral color pickers. Line width, range bands, band fill, trend change markers, bar coloring, and background coloring can each be adjusted or toggled so the chart stays as clean or as expressive as the workflow requires.
snapshot

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.