Indicator · Pine Script v5 · On the chart

Vol Box

by namuan· code credited to voided

Calculates realized volatility by smoothing squared log returns with an exponential moving average annualized by periods per year.

View on GitHub

GitHub stars318on the repository
Pine versionv5runs as is
Lines of code49
Settings5inputs
LicenceMIT
Last update2 months ago18 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

49 lines of Pine Script v5 from tv-scripts/tvt-vol-box.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

tvt-vol-box.pine
// https://www.tradingview.com/script/xmcUc75j-vol-box/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © voided

//@version=5
indicator("vol_box", overlay = true)

stdevs  = input.float(title = "stdevs", defval = 1.0)
pp      = input.int(title = "periods to project", defval = 1)
window  = input.int(title = "window", defval = 20)
ppy     = input.int(title = "periods per year", defval = 252)
history = input.bool(title = "show history", defval = false)

var rvs = array.new_float()

squared_returns     = math.pow(math.log(close / close[1]), 2.0)
smoothed_returns    = ta.ema(squared_returns, window)
rv                  = math.sqrt(smoothed_returns * ppy)

array.push(rvs, rv)

upper   = close * (1 + rv * stdevs * math.sqrt(pp / ppy))
lower   = close * (1 - rv * stdevs * math.sqrt(pp / ppy))

var fcst    = array.new_int()

array.push(fcst, close <= upper[pp] and close >= lower[pp] ? 1 : 0)

hist_transp = history ? 0 : 100

hist_upper = close > upper[pp] ? color.new(color.red, hist_transp) : color.new(color.blue, hist_transp)
hist_lower = close < lower[pp] ? color.new(color.red, hist_transp) : color.new(color.blue, hist_transp)

plot(upper[pp], title = "upper bound", color = hist_upper, style = plot.style_stepline)
plot(lower[pp], title = "upper bound", color = hist_lower, style = plot.style_stepline)

if barstate.islast

    bgc = color.new(color.white, 100)
    bc  = color.new(color.blue, 0)

    pct_rnk = array.percentrank(rvs, array.indexof(rvs, rv))
    acc     = array.avg(fcst) * 100

    b_txt   = str.format("rv: {0,number,#.#}%\nrnk: {1, number, #.#}%\nacc: {2, number, #.#}%", rv * 100, pct_rnk, acc)

    b = box.new(left = bar_index + 1, top = upper, bottom = lower, right = bar_index + pp, xloc = xloc.bar_index, bgcolor = bgc, border_color = bc, text = b_txt, text_color = bc, text_halign = text.align_left, text_valign = text.align_top, text_size = size.tiny)

    box.delete(b[1])

Overview

Vol Box projects expected upper and lower price boundaries across a user-defined forward horizon, plotting them as step lines or displaying a forward projection box on the latest bar. The box reports realized volatility percentage, its percentile rank, and historical forecast accuracy. Key inputs configure standard deviations, projection periods, smoothing window, and annual period scaling. It overlays directly on the price chart.

Details

Published by

namuan on GitHub

Code credit

voided, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

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

trading-strategiesmarket-analysisdtalestock-market-analysistelegram-botearnings-calendaroptions-trading

Settings

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

SettingTypeDefaultVariable
stdevsfloat1.0stdevs
periods to projectint1pp
windowint20window
periods per yearint252ppy
show historyboolfalsehistory
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]

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

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

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