Indicator · Pine Script v6 · On the chart

Adaptive Decycler Supertrend

by ZhijuCen· code credited to SchizoQuant

The Adaptive Decycler Supertrend indicator plots an adaptive decycler baseline directly on the price chart.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code105
Settings14inputs
LicenceMIT
Last update2 weeks ago12 Oct 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

105 lines of Pine Script v6 from skills/mql5-from-pinescript/assets/pine-scripts/adaptive-decycler-supertrend.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

adaptive-decycler-supertrend.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 Decycler Supertrend", overlay=true)

// USER INPUTS
string cutoffTip     = "Minimum Cutoff sets the fastest Decycler response used during cleaner directional movement, while Maximum Cutoff sets the slowest response used during noisier conditions. Lower the minimum for faster reactions or increase the maximum for stronger smoothing."
string efficiencyTip = "Sets the lookback used to measure directional efficiency by comparing net price movement with the total distance travelled. Higher efficiency moves the adaptive Decycler toward the faster cutoff, while lower efficiency moves it toward the slower cutoff."
string rmsTip        = "Sets the lookback used to measure the root-mean-square energy of price displacement from the adaptive Decycler. Increase it for steadier bands or decrease it for faster adaptation to changes in residual movement."
string bandTip       = "Upper Multiplier controls the RMS distance above the adaptive Decycler, while Lower Multiplier controls the distance below it. Increase either multiplier to widen that side of the Supertrend structure and require a larger move before a reversal."
string colorTip      = "Bullish Color represents bullish Supertrend regimes, LONG signals, and bullish visual elements, while Bearish Color represents bearish Supertrend regimes, SHORT signals, and bearish visual elements."

float src             = input.source(title="Source", defval=close, group="Adaptive Decycler", tooltip="Choose the price source used by the adaptive Decycler, efficiency calculation, residual measurement, and Supertrend regime logic.")
int   minimumCutoff   = input.int(title="Minimum Cutoff", defval=15, minval=6, group="Adaptive Decycler", inline="D1", tooltip=cutoffTip)
int   maximumCutoff   = input.int(title="Maximum Cutoff", defval=50, minval=7, group="Adaptive Decycler", inline="D1", tooltip=cutoffTip)
int   efficiencyLength = input.int(title="Efficiency Length", defval=10, minval=2, group="Adaptive Decycler", tooltip=efficiencyTip)
int   rmsLength       = input.int(title="Residual RMS Length", defval=20, minval=2, group="Supertrend Bands", tooltip=rmsTip)
float upperMultiplier = input.float(title="Upper Multiplier", defval=2.00, minval=0.10, step=0.10, group="Supertrend Bands", inline="B1", tooltip=bandTip)
float lowerMultiplier = input.float(title="Lower Multiplier", defval=2.60, minval=0.10, step=0.10, group="Supertrend Bands", inline="B1", tooltip=bandTip)
bool  showDecycler    = input.bool(title="Show Decycler", defval=true, group="Visualization", tooltip="Show or hide the adaptive Decycler baseline. Turning this off only changes the chart display and does not affect the Supertrend calculations or signals.")
bool  showEnvelope    = input.bool(title="Show RMS Envelope", defval=false, group="Visualization", tooltip="Show or hide the upper and lower residual RMS bands. Turning this off only changes the chart display and does not affect regime calculations.")
bool  showFill        = input.bool(title="Show Envelope Fill", defval=true, group="Visualization", tooltip="Show or hide the shaded region between the RMS bands when the envelope is visible. This is visual only and does not affect the indicator calculations.")
bool  showSignals     = input.bool(title="Show Signals", defval=true, group="Visualization", tooltip="Show or hide LONG and SHORT markers whenever the active Supertrend regime changes. Turning this off does not change the underlying regime calculation.")
bool  colorBars       = input.bool(title="Color Bars", defval=true, group="Visualization", tooltip="Color price candles according to the active Supertrend 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
int fastLimit = math.min(minimumCutoff, maximumCutoff)
int slowLimit = math.max(minimumCutoff, maximumCutoff)

float direction = math.abs(src - nz(src[efficiencyLength], src))
float noise     = 0.0

for i = 0 to efficiencyLength - 1
    noise += math.abs(nz(src[i], src) - nz(src[i + 1], src))

float efficiency = noise > 0.0 ? direction / noise : 0.0
efficiency := math.max(0.0, math.min(1.0, efficiency))

float adaptiveCutoff = float(slowLimit) - efficiency * float(slowLimit - fastLimit)

float angle       = 2.0 * math.pi / adaptiveCutoff
float cosineValue = math.cos(angle)
float alpha       = math.abs(cosineValue) > 0.000001 ? (cosineValue + math.sin(angle) - 1.0) / cosineValue : 1.0
alpha := math.max(0.0, math.min(1.0, alpha))

var float decycler = na
decycler := na(decycler[1]) ? src : alpha * 0.5 * (src + nz(src[1], src)) + (1.0 - alpha) * decycler[1]

float residual       = src - decycler
float residualEnergy = ta.sma(residual * residual, rmsLength)
float residualRMS    = math.sqrt(math.max(nz(residualEnergy, 0.0), 0.0))
residualRMS := math.max(residualRMS, syminfo.mintick)

float upperEnvelope = decycler + residualRMS * upperMultiplier
float lowerEnvelope = decycler - residualRMS * lowerMultiplier

//SIGNALS
var int SQ           = src >= decycler ? 1 : -1
var float trendTrail = na

int previousSQ      = nz(SQ[1], SQ)
float previousTrail = nz(trendTrail[1], previousSQ == 1 ? lowerEnvelope : upperEnvelope)

bool long  = previousSQ == -1 and src > previousTrail
bool short = previousSQ == 1 and src < previousTrail

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

if SQ == 1
    trendTrail := long ? lowerEnvelope : math.max(lowerEnvelope, previousTrail)
else
    trendTrail := short ? upperEnvelope : math.min(upperEnvelope, previousTrail)

bool longSignal  = SQ == 1 and nz(SQ[1], SQ) != 1
bool shortSignal = SQ == -1 and nz(SQ[1], SQ) != -1

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

// PLOTS
plot(SQ == 1 ? trendTrail : na, title="Bullish Supertrend", color=longColor, linewidth=2, style=plot.style_linebr)
plot(SQ == -1 ? trendTrail : na, title="Bearish Supertrend", color=shortColor, linewidth=2, style=plot.style_linebr)
plot(showDecycler ? decycler : na, title="Adaptive Decycler", color=color.new(col, 35), linewidth=2)
upperPlot = plot(showEnvelope ? upperEnvelope : na, title="Upper RMS Band", color=color.new(shortColor, 70), linewidth=1)
lowerPlot = plot(showEnvelope ? lowerEnvelope : na, title="Lower RMS Band", color=color.new(longColor, 70), linewidth=1)
fill(upperPlot, lowerPlot, title="RMS Band Fill", color=showFill and showEnvelope ? color.new(col, 93) : na)
plot(efficiency, title="Efficiency", display=display.data_window)
plot(adaptiveCutoff, title="Adaptive Cutoff", display=display.data_window)
plot(residual, title="Decycler Residual", display=display.data_window)
plot(residualRMS, title="Residual RMS", display=display.data_window)
plotshape(showSignals and longSignal, title="Long Signal", style=shape.triangleup, location=location.belowbar, size=size.small, color=longColor, text="LONG", textcolor=color.white)
plotshape(showSignals and shortSignal, title="Short Signal", style=shape.triangledown, location=location.abovebar, size=size.small, color=shortColor, text="SHORT", textcolor=color.white)
barcolor(colorBars ? col : na)

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

Overview

Adaptive Decycler Supertrend adjusts its cutoff frequency between minimum and maximum bounds based on price efficiency measured over a chosen lookback period. Using the root-mean-square energy of price displacement from this baseline, it constructs volatility bands scaled by adjustable upper and lower multipliers to track trend regimes. Users can customize envelope visibility, display trend signals, and apply regime bar coloring.

Details

Published by

ZhijuCen on GitHub

Code credit

SchizoQuant, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Trend, Volatility & bands, Moving averages

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.

Settings

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

SettingTypeDefaultVariable
Sourcesourceclosesrc
Minimum Cutoffint15minimumCutoff
Maximum Cutoffint50maximumCutoff
Efficiency Lengthint10efficiencyLength
Residual RMS Lengthint20rmsLength
Upper Multiplierfloat2.00upperMultiplier
Lower Multiplierfloat2.60lowerMultiplier
Show DecyclerbooltrueshowDecycler
Show RMS EnvelopeboolfalseshowEnvelope
Show Envelope FillbooltrueshowFill
Show SignalsbooltrueshowSignals
Color BarsbooltruecolorBars
Show all 14 settings
SettingTypeDefaultVariable
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

318 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 2 months ago · MIT GitHub repository of Multiple Moving Averages

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

Bollinger Bands Force

by harryguiacorn
219 stars

This indicator modifies standard Bollinger Bands to measure directional trend force based on line alignment. It calculates a simple moving average basis along with upper and lower volatility bands. When all three lines move upward or downward simultaneously, i

Indicator v5 Volatility & bandsTrend
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Force

Adaptive MA Slope

by capissimo
114 stars

This indicator calculates Kaufman's Adaptive Moving Average (KAMA) on a chosen price source and determines trend direction based on the slope across a configurable lookback window. Signals can be filtered by short-term volatility expansion using ATR comparison

Indicator v4 Moving averagesTrend
Updated 1 year ago · None stated GitHub repository of Adaptive MA Slope

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