Indicator · Pine Script v6 · On the chart

Capital41 ATR Volatility Bands v2

by damianpitt· code credited to Capital41 | MIT License

Capital41 ATR Volatility Bands v2 draws ATR-based bands around a customizable basis moving average on the price chart to visualize potential volatility ranges.

View on GitHub

GitHub stars6on the repository
Pine versionv6current
Lines of code98
Settings10inputs
LicenceMIT
Last update8 weeks ago31 Aug 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

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

Capital41_ATR_Volatility_Bands_v2.pine
// Copyright (c) 2026 Capital41 | MIT License
// CAPITAL41 ATR VOLATILITY BANDS v2

// What it does:
// - Draws ATR-based bands around a moving average to visualize volatility range.
// - Optional recent-range box highlights the last N bars' high/low range.
// - Optional expansion highlight when ATR is rising above its average.
// - Alerts on volatility expansion and band crosses.
//
// v2 changes:
// - ADDED: Alert conditions for volatility expansion start and band crosses,
//          gated by barstate.isconfirmed.
//
// TradingView setup:
// 1) Open TradingView -> Pine Editor.
// 2) Paste this script, Save, and Add to chart.
// 3) Use 30m or 4h on BTC or US stocks.
// 4) Adjust ATR Multiplier to widen or tighten the bands.
//
// Usage guide (30m/4h):
// - Bands help spot expanding volatility and mean-reversion edges.
// - If price rides the band, trend is strong; if it rejects, expect pullback.
// - Volatility box shows recent range; use it with sweeps or session context.



//@version=6
indicator("Capital41 ATR Volatility Bands v2", overlay = true, max_boxes_count = 20)


// Inputs
basisType     = input.string("EMA", "Basis type", options = ["EMA", "SMA"])
basisLen      = input.int(50, "Basis length", minval = 5)
atrLen        = input.int(14, "ATR length", minval = 1)
atrMult       = input.float(1.5, "ATR multiplier", minval = 0.1, maxval = 5.0)

showBasis     = input.bool(false, "Show basis")
showBands     = input.bool(true, "Show ATR bands")
showVolBox    = input.bool(true, "Show recent-range box")
boxLookback   = input.int(20, "Range lookback bars", minval = 5, maxval = 200)

showExpansion = input.bool(false, "Highlight volatility expansion")
expFactor     = input.float(1.2, "Expansion factor", minval = 1.0, maxval = 3.0)

colorBand  = color.new(color.blue, 0)
colorBasis = color.new(color.gray, 0)
colorBox   = color.new(color.gray, 90)

// Basis + ATR
basis = basisType == "EMA" ? ta.ema(close, basisLen) : ta.sma(close, basisLen)
atr   = ta.atr(atrLen)
upper = basis + atr * atrMult
lower = basis - atr * atrMult


plot(showBasis ? basis : na, title = "Basis", color = colorBasis, linewidth = 1)
plot(showBands ? upper : na, title = "ATR Upper", color = color.new(colorBand, 40), linewidth = 1)
plot(showBands ? lower : na, title = "ATR Lower", color = color.new(colorBand, 40), linewidth = 1)


// Recent-range box
var box volBox = na
if showVolBox
    hi = ta.highest(high, boxLookback)
    lo = ta.lowest(low, boxLookback)
    left = bar_index - boxLookback + 1
    if na(volBox)
        volBox := box.new(left = left, right = bar_index, top = hi, bottom = lo, border_width = 0, bgcolor = colorBox)
    else
        box.set_left(volBox, left)
        box.set_right(volBox, bar_index)
        box.set_top(volBox, hi)
        box.set_bottom(volBox, lo)
else
    if not na(volBox)
        box.delete(volBox)
        volBox := na


// Expansion highlight
atrAvg = ta.sma(atr, atrLen)
volExp = atrAvg > 0 and atr > atrAvg * expFactor
bgcolor(showExpansion and volExp ? color.new(color.orange, 92) : na)


// Alerts (crosses hoisted so ta.* runs every bar, then confirmed on bar close)
expStart      = volExp and not volExp[1]
upperTagCross = ta.crossover(close, upper)
lowerTagCross = ta.crossunder(close, lower)

alertcondition(expStart and barstate.isconfirmed, title = "Volatility Expansion",
               message = "ATR Bands: volatility expansion started on {{ticker}} ({{interval}})")

alertcondition(upperTagCross and barstate.isconfirmed, title = "Upper Band Cross",
               message = "ATR Bands: price closed above the upper band on {{ticker}} ({{interval}})")

alertcondition(lowerTagCross and barstate.isconfirmed, title = "Lower Band Cross",
               message = "ATR Bands: price closed below the lower band on {{ticker}} ({{interval}})")

Overview

The basis can be set to EMA or SMA, with adjustable lengths for both basis and ATR. It optionally plots a recent-range box showing the last N bars high-low range and highlights volatility expansion when ATR exceeds its average by a factor. Band crosses and expansion starts trigger alerts gated on confirmed bars. Main settings control basis type, lengths, multipliers, and visibility toggles for basis, bands, box, and expansion. It draws directly on the price chart for intraday and swing timeframes.

Details

Published by

damianpitt on GitHub

Code credit

Capital41 | MIT License, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Volatility & bands

Markets

Any symbol

Timeframes

M15-H1, H4 and above

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

cryptoindicatorsmarket-structureorder-blockspinescriptsmart-moneytechnical-analysistechnical-analysis-indicatorstradingtradingview

Settings

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

SettingTypeDefaultVariable
Basis typestringEMAbasisType
Basis lengthint50basisLen
ATR lengthint14atrLen
ATR multiplierfloat1.5atrMult
Show basisboolfalseshowBasis
Show ATR bandsbooltrueshowBands
Show recent-range boxbooltrueshowVolBox
Range lookback barsint20boxLookback
Highlight volatility expansionboolfalseshowExpansion
Expansion factorfloat1.2expFactor
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

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

This indicator plots trade entry and exit signals on the price chart by combining Bollinger Bands with optional filter conditions. It calculates standard Bollinger Bands along with RSI, Aroon, and moving average filters. Reversal signals trigger when price bre

Indicator v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner IND [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

Algo AVT

by ricardosantos79
261 stars

This indicator calculates an outlier-filtered moving average based on statistical filtering concepts. It stores close prices in a rolling array over a user-defined length, calculates the mean and standard deviation, and excludes values falling within a specifi

Indicator v4 Moving averagesVolatility & bands
Updated 4 years ago · None stated GitHub repository of Algo AVT

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