Bilateral Filter Trend [QuantAlgo]

1 492

More exclusive indicators from QuantAlgo

Subscribe to QuantAlgo Essential for $49.99/month to get exclusive indicators by this author. You pay right on TradingView and can use them on your charts straight away.

Explore QuantAlgo Essential
🟢 Overview

The Bilateral Filter Trend is a trend-following indicator that brings the bilateral filter, an edge-preserving smoothing method from image processing, to price, so small fluctuations around a level are averaged away while a decisive move to a new level is followed promptly instead of being smoothed over across many bars. It weighs every bar in its window by both how recent it is and how close it traded to the current price level, with closeness measured in units of volatility, then confirms a trend change once the filter retraces a volatility-scaled distance from its extreme on a closed bar, so traders can follow trends with a smoothed line that sets aside the prices a breakout leaves behind, across every timeframe and market.
תמונת-בזק
🟢 How It Works

The indicator is built around the bilateral filter, an image processing technique named by Carlo Tomasi and Roberto Manduchi in their 1998 paper on filtering gray and color images. It averages each pixel with neighbors that are both close by and similar in brightness or color, so noise within a surface is smoothed away while the sharp edges between surfaces stay intact. Applied to price, “close by” means recent and “similar” means trading at a nearby level, which lets the filter treat a shift to a new price level as an edge to preserve rather than noise to average out. It has three stages: a volatility-scaled kernel width and a reference level that together define what counts as nearby, a two-kernel weighting that builds the filter, and a state engine that confirms trend changes once the filter retraces far enough from its extreme.

First, the scale and the reference are set. The range kernel width is the Range Sigma multiple of the 14-bar Average True Range, so what counts as a nearby level widens as the market turns volatile and narrows as it quiets. Every bar in the window is compared against a reference level, which by default is the median of the last three source values, so a single isolated spike is judged against where price has been rather than becoming the reference itself, while a move that holds for two bars shifts the reference to the new level. With Spike Rejection disabled, the current value serves as the reference on every bar:
Pine Script®

Next, the filter is built. Each bar receives two weights: a time weight that decays along a Gaussian curve of Time Sigma width as the bar gets older, and a range weight that falls off along a second Gaussian curve as its price sits farther from the reference, measured in range kernel widths. The filter is the window’s average weighted by the product of the two, so bars that are both recent and near the current level dominate, while bars that traded at another level fade out however recent they are. Swings wider than the range kernel are treated as level changes as well, so inside a wide, choppy range the filter follows price more closely than a conventional moving average would. The share of the time weight that the range kernel sets aside is kept as the edge strength, which rises as price moves away from the levels it traded at earlier in the window and sets the brightness of the glow:
Pine Script®

Finally, the state engine confirms trend changes. The reversal distance is the Reversal Threshold multiplied by the range kernel width, so it scales with volatility as well. A bullish trend turns bearish on the closed bar where the filter has fallen the reversal distance below its highest level since the trend began, and a bearish trend turns bullish once it has risen the same distance above its lowest level since that trend began, while from the warm-up state the first trend is set the same way from the filter’s highest and lowest levels so far. Each new trend tracks its extreme from the bar that confirms it, and states update on confirmed bars, so a confirmed trend change stays in place once the bar closes:
Pine Script®

תמונת-בזק
🟢 Signal Interpretation

▶ Bullish Trend (Filter Line in Bullish Color): When a bullish trend is confirmed, the filter line, glow, and similarity band take on the bullish color, reading as buyers lifting price to higher levels and holding it there long enough for the filter to follow. Treat this as a long bias: pullbacks leave the trend intact as long as the filter stays within the reversal distance of its high, and the bias ends once it falls that far, which turns the trend bearish.

▶ Bearish Trend (Filter Line in Bearish Color): When a bearish trend is confirmed, the line, glow, and band turn to the bearish color, reading as sellers driving price to lower levels and sustaining the move until the filter follows. Treat this as a short bias: bounces leave the trend intact as long as the filter stays within the reversal distance of its low, and the bias ends once it rises that far, which turns the trend bullish.
תמונת-בזק
🟢 Features

▶ Preconfigured Presets: Three parameter sets for different trading styles and timeframes. “Default” delivers balanced trend tracking for swing trading on 1H to daily charts, with the window length, time sigma, range sigma, and reversal threshold adjustable directly. “Fast Response” is built for intraday trading on 5-minute to 1H charts, shortening the window and narrowing both kernels, which also reduces the retrace needed to confirm a reversal, so the filter tracks price closely and trend changes confirm sooner. “Smooth Trend” is aimed at position trading on daily and weekly charts, lengthening the window, widening the time kernel, and raising the reversal threshold so trends hold through deeper pullbacks and trend changes confirm less often.
תמונת-בזק
▶ Built-in Alerts: Three alert conditions support hands-off monitoring. “Bullish Trend Signal” fires on the closed bar that confirms a bullish trend. “Bearish Trend Signal” fires on the closed bar that confirms a bearish trend. “Any Trend Change” fires on either change. Alert messages include exchange, ticker, and timeframe for immediate context.
תמונת-בזק
▶ Visual Customization: Six color presets (Classic, Aqua, Cosmic, Cyber, Neon, and Custom) apply coordinated bullish and bearish colors to the filter line, a glow that brightens with the edge strength, a similarity band that shades one range kernel width on each side of the filter, optional bar coloring, and optional background coloring. The bullish and bearish color pickers apply when Custom is selected. The glow, band, and both coloring options can each be toggled, with adjustable transparency for the bar and background tints, so the chart stays as clean or as expressive as the workflow requires.
תמונת-בזק

כתב ויתור

המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.