Indicator · Pine Script v6 · On the chart

Adaptive Ehlers Filtered Percentile

by theonetrade· code credited to SchizoQuant

Adaptive Ehlers Filtered Percentile is a technical indicator that calculates a volatility-adaptive moving average smoothed by a nonlinear Ehlers filter.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code95
Settings17inputs
LicenceMIT
Last update2 weeks ago8 Nov 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

95 lines of Pine Script v6 from assets/indicator/bit-exact/adaptive_ehlers_filtered_percentile_zdQ2A3zf.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

adaptive_ehlers_filtered_percentile_zdQ2A3zf.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SchizoQuant

//@version=6
indicator("Adaptive Ehlers Filtered Percentile", overlay=true)

// USER INPUTS
string adaptivePeriodTip = "Minimum MA Period sets the fastest adaptive response used during higher volatility, while Maximum MA Period sets the slowest response used during calmer conditions. Lower the minimum for quicker reactions, and increase the maximum for a smoother baseline."
string ehlersTip         = "Filter Length controls how many Adaptive MA observations contribute to the nonlinear Ehlers filter, while Momentum Length controls how far apart those observations are compared when calculating their weights. Increase Filter Length for a smoother trendline, and increase Momentum Length to emphasize broader price displacement."
string percentileTip     = "Percentile Length sets how much historical price-to-filter displacement is ranked, while Percentile Level selects which ranked distance becomes the base band width. Increase the length for a broader sample and increase the percentile level for wider, more selective bands."
string multiplierTip     = "Upper Band Multiplier scales the percentile distance above the filtered trend, while Lower Band Multiplier scales the distance below it. Increase either multiplier to widen that side of the regime threshold and require a larger price move before a breakout."
string colorTip          = "Bullish Color is used for bullish regimes, LONG signals, the upper band, and bullish candle coloring, while Bearish Color is used for bearish regimes, SHORT signals, the lower band, and bearish candle coloring."

float maSrc           = input.source(title="Source", defval=close, group="Adaptive MA Settings", tooltip="Choose the price source used to calculate the volatility-adaptive moving average.")
int   maMin           = input.int(title="Minimum MA Period", defval=3, minval=1, group="Adaptive MA Settings", inline="AMA1", tooltip=adaptivePeriodTip)
int   maMax           = input.int(title="Maximum MA Period", defval=30, minval=2, group="Adaptive MA Settings", inline="AMA1", tooltip=adaptivePeriodTip)
int   volLen          = input.int(title="Volatility Period", defval=9, minval=2, group="Adaptive MA Settings", tooltip="Sets the lookback used to measure the standard deviation of price changes and adapt the moving average length. Increase it for steadier adaptation or decrease it for faster reactions to changing volatility.")
int   ehlersLength    = input.int(title="Filter Length", defval=9, minval=2, group="Ehlers Filter", inline="EF1", tooltip=ehlersTip)
int   ehlersMomentum  = input.int(title="Momentum Length", defval=15, minval=1, group="Ehlers Filter", inline="EF1", tooltip=ehlersTip)
int   percentileLen   = input.int(title="Percentile Length", defval=50, minval=2, group="Percentile Bands", inline="PB1", tooltip=percentileTip)
float percentileLevel = input.float(title="Percentile Level", defval=75.0, minval=1.0, maxval=99.0, step=1.0, group="Percentile Bands", inline="PB1", tooltip=percentileTip)
float upperMult       = input.float(title="Upper Band Multiplier", defval=0.7, minval=0.1, step=0.1, group="Percentile Bands", inline="PB2", tooltip=multiplierTip)
float lowerMult       = input.float(title="Lower Band Multiplier", defval=0.7, minval=0.1, step=0.1, group="Percentile Bands", inline="PB2", tooltip=multiplierTip)
bool  showMA          = input.bool(title="Show Adaptive Filter", defval=true, group="Visualization", tooltip="Show or hide the Ehlers-filtered Adaptive MA. Turning this off only changes the chart display and does not affect the calculations or signals.")
bool  showBands       = input.bool(title="Show Percentile Bands", defval=true, group="Visualization", tooltip="Show or hide the upper and lower percentile bands. Turning this off only changes the chart display and does not affect the regime calculations.")
bool  showFill        = input.bool(title="Show Band Fill", defval=true, group="Visualization", tooltip="Show or hide the shaded area between the upper and lower percentile bands. This is visual only and does not change the indicator calculations.")
bool  showSignals     = input.bool(title="Show Signals", defval=true, group="Visualization", tooltip="Show or hide LONG and SHORT markers whenever price establishes a new percentile-band regime. Turning this off does not change the underlying regime state.")
bool  colorBars       = input.bool(title="Color Bars", defval=true, group="Visualization", tooltip="Color price candles according to the currently active regime. Turning this off only removes candle coloring and does not affect signals.")
color longColor       = input.color(title="Bullish Color", defval=color.rgb(57, 255, 20), group="Color Settings", inline="C1", tooltip=colorTip)
color shortColor      = input.color(title="Bearish Color", defval=color.rgb(138, 43, 226), group="Color Settings", inline="C1", tooltip=colorTip)

// CALCULATIONS
float deltaP   = maSrc - maSrc[1]
float s        = ta.stdev(deltaP, volLen)
float sAverage = ta.sma(s, volLen)

float sMin     = sAverage * 0.25
float sMax     = sAverage * 1.75
float volRange = sMax - sMin

float adaptiveLength = volRange > 0.0 ? (s <= sMin ? maMax : s >= sMax ? maMin : maMax - (maMax - maMin) * (s - sMin) / volRange) : maMax
float alpha          = 2.0 / (adaptiveLength + 1.0)

var float adaptiveMA = na
adaptiveMA := na(adaptiveMA[1]) ? maSrc : adaptiveMA[1] + alpha * (maSrc - adaptiveMA[1])

float ehlersNumerator      = 0.0
float ehlersCoefficientSum = 0.0

for i = 0 to ehlersLength - 1
    float currentSample   = adaptiveMA[i]
    float referenceSample = adaptiveMA[i + ehlersMomentum]
    if not na(currentSample) and not na(referenceSample)
        float coefficient = math.abs(currentSample - referenceSample)
        ehlersNumerator      += coefficient * currentSample
        ehlersCoefficientSum += coefficient

float ehlersFallback = ta.sma(adaptiveMA, ehlersLength)
float trendMA        = ehlersCoefficientSum > 0.0 ? ehlersNumerator / ehlersCoefficientSum : ehlersFallback

float deviation          = math.abs(maSrc - trendMA)
float percentileDistance = ta.percentile_nearest_rank(deviation, percentileLen, percentileLevel)

float upperBand = trendMA + percentileDistance * upperMult
float lowerBand = trendMA - percentileDistance * lowerMult

// SIGNALS
bool long  = maSrc > upperBand
bool short = maSrc < lowerBand

var int SQ = 0

if long
    SQ := 1
else if short
    SQ := -1

bool longSignal  = SQ == 1 and SQ[1] != 1
bool shortSignal = SQ == -1 and SQ[1] != -1

// COLORS
color col = SQ == 1 ? longColor : shortColor

// PLOTS
plot(showMA ? trendMA : na, title="Adaptive Ehlers Filter", color=col, linewidth=2)
upperPlot = plot(showBands ? upperBand : na, title="Upper Percentile Band", color=color.new(longColor, 35), linewidth=1)
lowerPlot = plot(showBands ? lowerBand : na, title="Lower Percentile Band", color=color.new(shortColor, 35), linewidth=1)
fill(upperPlot, lowerPlot, title="Percentile Band Fill", color=showFill ? color.new(col, 92) : na)
plotshape(showSignals and longSignal, title="Long Signal", style=shape.triangleup, location=location.belowbar, color=longColor, size=size.small, text="LONG", textcolor=color.white)
plotshape(showSignals and shortSignal, title="Short Signal", style=shape.triangledown, location=location.abovebar, color=shortColor, size=size.small, text="SHORT", textcolor=color.white)
barcolor(colorBars ? col : na)

// ALERTS
alertcondition(longSignal, title="Long Signal", message="Adaptive Ehlers Filtered Percentile Long Signal on {{ticker}}")
alertcondition(shortSignal, title="Short Signal", message="Adaptive Ehlers Filtered Percentile Short Signal on {{ticker}}")

Overview

Adaptive Ehlers Filtered Percentile plots dynamic upper and lower volatility bands around the baseline based on historical percentile price displacements. The indicator draws directly on the price chart, featuring optional regime signals, custom bar coloring, and filled bands. Main settings allow customization of adaptive moving average periods, volatility lookback, Ehlers filter length, percentile thresholds, and band multipliers.

Details

Published by

theonetrade on GitHub

Code credit

SchizoQuant, as written in the script's header

Draws

On the price chart

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

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
SourcesourceclosemaSrc
Minimum MA Periodint3maMin
Maximum MA Periodint30maMax
Volatility Periodint9volLen
Filter Lengthint9ehlersLength
Momentum Lengthint15ehlersMomentum
Percentile Lengthint50percentileLen
Percentile Levelfloat75.0percentileLevel
Upper Band Multiplierfloat0.7upperMult
Lower Band Multiplierfloat0.7lowerMult
Show Adaptive FilterbooltrueshowMA
Show Percentile BandsbooltrueshowBands
Show all 17 settings
SettingTypeDefaultVariable
Show Band FillbooltrueshowFill
Show SignalsbooltrueshowSignals
Color BarsbooltruecolorBars
Bullish Colorcolorcolor.rgb(57, 255, 20)longColor
Bearish Colorcolorcolor.rgb(138, 43, 226)shortColor
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

GEKO Gold

by grzegorzkowalskigk-jpg
4 stars

GEKO Gold is a trend-following indicator for gold (XAUUSD/MGC). It computes a GEKO-TIMID composite trend strength score by blending weekly and daily EMAs and ADX values, then classifies the trend into Emerging, Dominant or Extended states. The indicator plots

Indicator v6 TrendMoving averages
Updated 4 months ago · Custom licence GitHub repository of GEKO Gold
1 stars

V10 Swing Sniper (KLSE) is a daily chart overlay indicator designed for swing trading Bursa Malaysia equities based on Mark Minervini's Stage 2 and Volatility Contraction Pattern (VCP) principles. It calculates exponential moving averages, relative strength ag

Indicator v5 TrendBreakout
Updated 5 months ago · None stated GitHub repository of V10 Swing Sniper (KLSE)
1 stars

This indicator detects long-only trading setups centered on volume-weighted average price (VWAP) reclaim sequences. It calculates VWAP with standard deviation bands, tracking slope and price bias through an exponential moving average. Signals trigger on either

Indicator v6 TrendMoving averages
Updated 4 weeks ago · None stated GitHub repository of VWAP Reclaim (LONG-only) Indicator

EMA Breakout

by jerryinyang
5 stars

This indicator calculates and plots the exponential moving average on the chart, along with Keltner Channel bands. It applies optional filters based on Keltner Channel and Money Flow to identify breakout signals. Breakouts occur when price crosses the EMA with

Indicator v4 TrendMoving averages
Updated 2 years ago · None stated GitHub repository of EMA Breakout
321 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 8 days ago · MIT GitHub repository of Multiple Moving Averages

More Moving averages scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers