Indicator · Pine Script v6 · On the chart

L1 Proximal Filter [LuxAlgo]

by MeridianAlgo· code credited to LuxAlgo

This indicator implements an L1 proximal regularized filter to smooth price action while preserving significant market trends.

View on GitHub

GitHub stars9on the repository
Pine versionv6current
Lines of code83
Settings3inputs
LicenceMIT
Last update4 months ago29 Jun 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

83 lines of Pine Script v6 from examples/Proximal_Range_Filter_LuxAlgo.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

Proximal_Range_Filter_LuxAlgo.pine
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo

//@version=6
indicator("L1 Proximal Filter [LuxAlgo]", "LuxAlgo - L1 Proximal Filter", overlay = true)

//---------------------------------------------------------------------------------------------------------------------}
// Constants
//---------------------------------------------------------------------------------------------------------------------{
color BULL_COLOR    = #089981
color BEAR_COLOR    = #f23645

//---------------------------------------------------------------------------------------------------------------------}
// Inputs
//---------------------------------------------------------------------------------------------------------------------{
srcInput           = input.source(close, "Source")
atrMultInput       = input.float(1.5, "ATR Multiplier", minval = 0, step = 0.1, tooltip = "Defines the noise threshold by multiplying the 200-period ATR.")
muInput            = input.float(0.6, "Adaptation Rate (μ)", minval = 0, maxval = 1, step = 0.1, tooltip = "Controls how fast the filter adapts to price changes.")

//---------------------------------------------------------------------------------------------------------------------}
// Calculations
//---------------------------------------------------------------------------------------------------------------------{
// Determine the actual threshold to use
float threshold = ta.atr(200) * atrMultInput


// L1 Proximal Filter State
var float z = na
var float v = 0.0

if bar_index == 0
    z := srcInput
else
    // Prediction step based on previous state
    float zPrev = z[1]
    float vPrev = v[1]
    float zPred = zPrev + vPrev
    
    // Adaptation step: blend prediction with new data
    float zTemp = zPred + muInput * (srcInput - zPred)
    
    // Innovation (velocity) calculation with L1 soft-thresholding
    float diff = zTemp - zPrev
    
    if math.abs(diff) > threshold
        v := math.sign(diff) * (math.abs(diff) - threshold)
    else
        v := 0.0
        
    // Update filtered state
    z := zPrev + v

// Trend Logic (Binary State)
var int trend = 0
if z > z[1]
    trend := 1
else if z < z[1]
    trend := -1

bool upChange   = trend == 1  and trend[1] == -1
bool downChange = trend == -1 and trend[1] == 1

//---------------------------------------------------------------------------------------------------------------------}
// Visuals
//---------------------------------------------------------------------------------------------------------------------{
color zColor = trend == 1 ? BULL_COLOR : BEAR_COLOR
zPlot        = plot(z, "L1 Proximal Filter", color = zColor, linewidth = 3)
srcPlot      = plot(srcInput, "Source Plot", color = na)

// Vertical Gradient Fill
bool showFill   = (trend == 1 and srcInput > z) or (trend == -1 and srcInput < z)
fillTopColor    = showFill ? color.new(zColor, 50) : na
fillBottomColor = showFill ? color.new(zColor, 100) : na

fill(srcPlot, zPlot, srcInput, z, fillTopColor, fillBottomColor, "Trend Fill")

// Trend Change Dots
float switchVal   = upChange or downChange ? z[1] : na
color switchColor = upChange ? BULL_COLOR : BEAR_COLOR

plot(switchVal, "Trend Switch Dot", color = switchColor, style = plot.style_circles, linewidth = 4, offset = -1)

//---------------------------------------------------------------------------------------------------------------------{

Overview

L1 Proximal Filter [LuxAlgo] calculates a dynamic noise threshold based on a 200-period ATR and applies soft-thresholding to estimated velocity updates. The indicator plots the resulting adaptive filter line directly on the price chart, colored green for uptrends and red for downtrends. It also displays gradient fills between price and the filter line, along with circle markers indicating trend direction changes. Adjustable parameters include the price source, ATR multiplier, and adaptation rate.

Details

Published by

MeridianAlgo on GitHub

Code credit

LuxAlgo, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Trend, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

code-converterconverterjavascriptpinescripttranspilercode-reviewmeridianalgocode-conversionpinescript-algorithms

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
SourcesourceclosesrcInput
ATR Multiplierfloat1.5atrMultInput
Adaptation Rate (μ)float0.6muInput
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Chandelier Exit

by everget
948 stars

This indicator plots an ATR-based Chandelier Exit trailing stop on the price chart. It tracks a long stop under recent highs and a short stop above recent lows, then switches direction when price crosses the opposite stop. Buy and sell labels mark those flips.

Indicator v6 Volatility & bandsTrend Repaints
Updated 10 days ago · GPL-3.0 GitHub repository of Chandelier Exit

The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha

Indicator v5 Oscillators & momentumTrend
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup
330 stars

Range Filter [Alorse] is a technical indicator overlay for TradingView designed to filter market volatility and identify price trends. It calculates a smoothed range based on historical volatility using a configurable sampling period and multiplier applied to

Indicator v5 TrendVolatility & bands
Updated 2 months ago · None stated GitHub repository of Range Filter [Alorse]
318 stars

This indicator calculates an ATR trailing stop line derived from the highest high minus an average true range multiple over a specified lookback period. It plots the trailing stop line directly on the price chart and colors price bars based on whether the clos

Indicator v5 TrendVolatility & bands
Updated 2 months ago · MIT GitHub repository of ATR Trailing Stoploss

NVDA Trend Ribbon

by longsurf-ai
277 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of NVDA Trend Ribbon

[RS]Donchian Fans

by ricardosantos79
261 stars

This indicator plots Donchian Channel boundary lines along with dynamic fan projections directly on the price chart. It calculates the highest high, lowest low, and median price over a customizable lookback period. Whenever price establishes a new channel high

Indicator v4 Support & resistanceTrend
Updated 4 years ago · None stated GitHub repository of [RS]Donchian Fans

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers