Indicator · Pine Script v5 · On the chart

Vol Cone

by namuan· code credited to voided

This overlay indicator estimates annualized realized volatility from an exponential moving average of squared log returns.

View on GitHub

GitHub stars318on the repository
Pine versionv5runs as is
Lines of code148
Settings10inputs
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

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

tvt-vol-cone.pine
// https://www.tradingview.com/script/8UKvXuyX-vol-cone/
// 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_cone", overlay = true, max_lines_count = 500)

stdevs          = input.float(title = "stdevs", defval = 1.0)
stdevs_2        = input.float(title = "stdevs_2", defval = 2.0)
pp              = input.int(title = "periods to project", defval = 30)
window          = input.int(title = "window", defval = 21)
ppy             = input.int(title = "periods per year", defval = 252)
history         = input.bool(title = "show history", defval = false)
rate            = input.float(title = "interest rate", defval = 3.0) / 100
lags            = input.int(title = "lags", defval = 0)
show_stdevs_2   = input.bool(title = "show_stdevs_2", defval = true)
anchor          = input.bool(title = "anchor_to_session_start", 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)

one_year_ms = 252 * 24 * 60 * 60 * 1000
res         = 100
var lns_up      = array.new_line()
var lns_dn      = array.new_line()
var lns_up_2    = array.new_line()
var lns_dn_2    = array.new_line()

while array.size(lns_up) < pp

    for i = 0 to pp - 1

        array.push(lns_up, line.new(x1 = 0, x2 = 0, y1 = 0, y2 = 0, xloc = xloc.bar_index))
        array.push(lns_dn, line.new(x1 = 0, x2 = 0, y1 = 0, y2 = 0, xloc = xloc.bar_index))
        array.push(lns_up_2, line.new(x1 = 0, x2 = 0, y1 = 0, y2 = 0, xloc = xloc.bar_index, color = color.red))
        array.push(lns_dn_2, line.new(x1 = 0, x2 = 0, y1 = 0, y2 = 0, xloc = xloc.bar_index, color = color.red))

if barstate.islast

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

    if anchor and timeframe.isintraday

        for i = 0 to 5000

            if time[i + 1] - time[i + 2] != time[i + 2] - time[i + 3]

                lags := i + 2

                break

    x0      = bar_index[lags]
    y0_up   = close[lags]
    y0_up_2 = close[lags]
    y0_dn   = close[lags]
    y0_dn_2 = close[lags]
    dy_up   = 0.0
    dy_up_2 = 0.0
    dy_dn   = 0.0
    dy_dn_2 = 0.0
    fp      = 0.0

    for i = 0 to pp - 1

        fp      := close[lags] * math.exp(rate * (i + 1) * 1 / ppy)

        dy_up   := fp * math.exp(rv * stdevs * math.sqrt((i + 1) * 1 / ppy)) - y0_up
        dy_dn   := y0_dn - fp / math.exp(rv * stdevs * math.sqrt((i + 1) * 1 / ppy))

        dy_up_2 := fp * math.exp(rv * stdevs_2 * math.sqrt((i + 1) * 1 / ppy)) - y0_up_2
        dy_dn_2 := y0_dn_2 - fp / math.exp(rv * stdevs_2 * math.sqrt((i + 1) * 1 / ppy))

        up_ln = array.get(lns_up, i)
        dn_ln = array.get(lns_dn, i)

        line.set_x1(up_ln, x0)
        line.set_x2(up_ln, x0 + 1)
        line.set_y1(up_ln, y0_up)
        line.set_y2(up_ln, y0_up + dy_up)

        line.set_x1(dn_ln, x0)
        line.set_x2(dn_ln, x0 + 1)
        line.set_y1(dn_ln, y0_dn)
        line.set_y2(dn_ln, y0_dn - dy_dn)

        if show_stdevs_2

            up_ln_2 = array.get(lns_up_2, i)
            dn_ln_2 = array.get(lns_dn_2, i)

            line.set_x1(up_ln_2, x0)
            line.set_x2(up_ln_2, x0 + 1)
            line.set_y1(up_ln_2, y0_up_2)
            line.set_y2(up_ln_2, y0_up_2 + dy_up_2)

            line.set_x1(dn_ln_2, x0)
            line.set_x2(dn_ln_2, x0 + 1)
            line.set_y1(dn_ln_2, y0_dn_2)
            line.set_y2(dn_ln_2, y0_dn_2 - dy_dn_2)


        x0      := x0 + 1
        y0_up   := y0_up + dy_up
        y0_dn   := y0_dn - dy_dn
        y0_up_2 := y0_up_2 + dy_up_2
        y0_dn_2 := y0_dn_2 - dy_dn_2

    var t = table.new(position = position.top_right, columns = 2, rows = 7)

    table.cell(t, 0, 0, text = "rv")
    table.cell(t, 0, 1, text = "rnk")
    table.cell(t, 0, 2, text = "acc")
    table.cell(t, 0, 3, text = "up")
    table.cell(t, 0, 4, text = "dn")

    table.cell(t, 1, 0, text = str.format("{0, number, #.#}", rv * 100))
    table.cell(t, 1, 1, text = str.format("{0, number, #.#}", pct_rnk))
    table.cell(t, 1, 2, text = str.format("{0, number, #.#}", acc))
    table.cell(t, 1, 3, text = str.format("{0, number, #.####}", y0_up + dy_up))
    table.cell(t, 1, 4, text = str.format("{0, number, #.####}", y0_dn - dy_dn))

    if show_stdevs_2

        table.cell(t, 0, 5, text = "up_2")
        table.cell(t, 0, 6, text = "dn_2")
        table.cell(t, 1, 5, text = str.format("{0, number, #.####}", y0_up_2 + dy_up_2))
        table.cell(t, 1, 6, text = str.format("{0, number, #.####}", y0_dn_2 - dy_dn_2))

Overview

Vol Cone plots lagged upper and lower price bounds and, on the last bar, draws a forward cone of projected prices using an interest-rate drift and one or two volatility multiples. Settings change the lookback, projection length, periods per year, standard deviations, rate, lag, history visibility, and optional session-start anchoring on intraday charts. It is not a strategy and has no entry or exit rules.

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

Stocks

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
stdevs_2float2.0stdevs_2
periods to projectint30pp
windowint21window
periods per yearint252ppy
show historyboolfalsehistory
interest ratefloat3.0rate
lagsint0lags
show_stdevs_2booltrueshow_stdevs_2
anchor_to_session_startboolfalseanchor
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