Indicator · Pine Script v6 · On the chart

Adaptive Price Zone

by mihakralj

The Adaptive Price Zone indicator calculates volatility bands around a double-smoothed exponential moving average baseline directly on the price chart.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code70
Settings3inputs
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

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

apz.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Adaptive Price Zone", "APZ", overlay=true)

//@function Calculates Adaptive Price Zone using double-smoothed EMA
//@param source Series to calculate middle line from
//@param period Lookback period (sqrt applied internally for smoothing)
//@param bandPct Band width multiplier
//@returns tuple with [middle, upper, lower] band values
//@optimized Uses compound warmup compensation for nested EMAs, O(1) complexity per bar
apz(series float source, simple int period, simple float bandPct) =>
    if period <= 0
        runtime.error("Period must be greater than 0")
    if period > 5000
        runtime.error("Period exceeds maximum of 5000")
    if bandPct <= 0.0
        runtime.error("Band multiplier must be greater than 0")

    float smoothPeriod = math.sqrt(period)
    float alpha = 2.0 / (smoothPeriod + 1.0)
    float beta = 1.0 - alpha

    var float ema1_price = 0.0
    var float ema2_price = 0.0
    var float ema1_range = 0.0
    var float ema2_range = 0.0
    var float e = 1.0
    var bool warmup = true

    float current_price = nz(source)
    float current_range = nz(high - low)

    ema1_price := alpha * current_price + beta * ema1_price
    ema2_price := alpha * ema1_price + beta * ema2_price

    ema1_range := alpha * current_range + beta * ema1_range
    ema2_range := alpha * ema1_range + beta * ema2_range

    float middle = ema2_price
    float adaptiveRange = ema2_range

    if warmup
        e *= beta * beta
        float compensator = 1.0 / (1.0 - e)
        middle := compensator * ema2_price
        adaptiveRange := compensator * ema2_range
        warmup := e > 1e-10

    float width = bandPct * adaptiveRange
    float upper = middle + width
    float lower = middle - width

    [middle, upper, lower]

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

// Inputs
i_period = input.int(20, "Period", minval=1, maxval=5000)
i_bandPct = input.float(2.0, "Band Multiplier", minval=0.001, step=0.1)
i_source = input.source(close, "Source")

// Calculation
[middle, upper, lower] = apz(i_source, i_period, i_bandPct)

// Plot
plot(middle, "Middle", color=color.yellow, linewidth=2)
p1 = plot(upper, "Upper", color=color.new(color.yellow, 50), linewidth=1)
p2 = plot(lower, "Lower", color=color.new(color.yellow, 50), linewidth=1)
fill(p1, p2, color=color.new(color.yellow, 90), title="Band Fill")

Overview

Adaptive Price Zone calculates internal smoothing factors using the square root of the user-specified period, double-smoothing both the source price and the bar price range. Upper and lower bands are formed by offsetting the baseline using a multiple of the smoothed range. Key input parameters allow configuration of the lookback period, band multiplier, and source price.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Volatility & bands, Trend, 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.

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
Periodint20i_period
Band Multiplierfloat2.0i_bandPct
Sourcesourceclosei_source
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