Indicator · Pine Script v6 · On the chart

Decay Min-Max Channel

by mihakralj

Decay Min-Max Channel plots a price channel whose upper and lower bounds decay toward their midpoint.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code77
Settings1inputs
LicenceApache-2.0
Last update4 weeks ago27 Sep 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

77 lines of Pine Script v6 from lib/channels/decaychannel/decaychannel.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

decaychannel.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Decay Min-Max Channel (DECAYCHANNEL)", "DECAYCHANNEL", overlay=true)

//@function Calculates the Decaying Min-Max Channel with decay towards midpoint
//@param period Lookback period (period > 0)
//@param hi Source series for the highest high calculation (usually high)
//@param lo Source series for the lowest low calculation (usually low)
//@returns Tuple containing [decaying_highest_high, decaying_lowest_low]
//@optimized Uses exponential decay with O(n) complexity per bar
decaychannel(simple int period, series float hi = high, series float lo = low) =>
    if period <= 0
        runtime.error("Period must be > 0")
    float decayLambda = math.log(2.0) / period
    var float[] hbuf = array.new_float(period, na)
    var float[] lbuf = array.new_float(period, na)
    var float currentMax = na
    var float currentMin = na
    var int timeSinceNewMax = 0
    var int timeSinceNewMin = 0
    int idx = bar_index % period
    array.set(hbuf, idx, hi)
    array.set(lbuf, idx, lo)
    float periodMax = na
    float periodMin = na
    float periodSum = 0.0
    int validCount = 0
    for i = 0 to period - 1
        float hVal = array.get(hbuf, i)
        float lVal = array.get(lbuf, i)
        if not na(hVal) and not na(lVal)
            periodMax := na(periodMax) ? hVal : math.max(periodMax, hVal)
            periodMin := na(periodMin) ? lVal : math.min(periodMin, lVal)
            periodSum := periodSum + (hVal + lVal) / 2.0
            validCount := validCount + 1
    float periodAverage = validCount > 0 ? periodSum / validCount : (hi + lo) / 2.0
    if na(currentMax) or na(currentMin)
        currentMax := na(periodMax) ? hi : periodMax
        currentMin := na(periodMin) ? lo : periodMin
        timeSinceNewMax := 0
        timeSinceNewMin := 0
    else
        if hi >= currentMax
            currentMax := hi
            timeSinceNewMax := 0
        else
            timeSinceNewMax := timeSinceNewMax + 1
        if lo <= currentMin
            currentMin := lo
            timeSinceNewMin := 0
        else
            timeSinceNewMin := timeSinceNewMin + 1
        if validCount > 0
            float midpoint = (currentMax + currentMin) / 2.0
            float maxDecayRate = 1 - math.exp(-decayLambda * timeSinceNewMax)
            float minDecayRate = 1 - math.exp(-decayLambda * timeSinceNewMin)
            currentMax := currentMax - maxDecayRate * (currentMax - midpoint)
            currentMin := currentMin - minDecayRate * (currentMin - midpoint)
            if not na(periodMax)
                currentMax := math.min(currentMax, periodMax)
            if not na(periodMin)
                currentMin := math.max(currentMin, periodMin)
    [currentMax, currentMin]

// ---------- Main loop ----------

// Inputs
i_period = input.int(100, "Period", minval=1)

// Calculation
[highest, lowest] = decaychannel(i_period)

// Plot
p1 = plot(highest, "Decaying High", color=color.yellow, linewidth=2)
p2 = plot(lowest, "Decaying Low", color=color.yellow, linewidth=2)
fill(p1, p2, color=color.new(color.blue, 90), title="Channel Fill")

Overview

Each bar it stores highs and lows in a rolling window, tracks the latest extremes, and applies exponential decay when no new high or low appears. The decay constant is the natural log of two divided by the period. Bounds are also limited by the window maximum and minimum. It draws both lines on the price chart with a light blue fill. The only input is Period, default 100. It does not generate trade signals.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Support & resistance, 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

algorithmic-tradingcsharpdotnetpinescriptpythonquantitative-financesimdta-libtechnical-analysistechnical-indicators

Settings

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

SettingTypeDefaultVariable
Periodint100i_period
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

ICT Liquidity Void Fill

by ArunKBhaskar
575 stars

This overlay indicator marks ICT liquidity void fills on the price chart and can show long and short signals. It places a Fibonacci level inside a displacement candle, defaulting to the midpoint, and draws lines in a chosen style. Optional filters limit the fi

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Liquidity Void Fill

[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

Snag - VWAP

by dearvn
257 stars

This indicator plots a custom Anchored Volume-Weighted Average Price (VWAP) directly on the price chart along with optional standard deviation bands. Users can anchor the VWAP to standard time periods like sessions, weeks, or months, or to corporate events suc

Indicator v5 Moving averagesVolatility & bands Repaints
Updated 6 weeks ago · None stated GitHub repository of Snag - VWAP

Candlestick Patterns

by harryguiacorn
219 stars

This indicator plots optional candlestick pattern signals on the price chart. It detects engulfing bars, inside bars, HOLP and LOHP, kicker patterns, body-mass extremes, higher highs and lower lows, ATR warnings, and four-bar fractals. Optional pivot marks use

Indicator v5 Candlestick patternsVolatility & bands
Updated 1 year ago · None stated GitHub repository of Candlestick Patterns

Dynamic Linear Regression

by TradersPost
218 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 3 months ago · None stated GitHub repository of Dynamic Linear Regression

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