Indicator · Pine Script v6 · On the chart

VWAP with Standard Deviation Bands

by mihakralj

This indicator calculates a volume-weighted average price from a chosen source and the chart volume, then plots upper and lower bands at a chosen number of standard deviations.

View on GitHub

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

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

vwapsd.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("VWAP with Standard Deviation Bands", "VWAPSD", overlay=true)

//@function Calculate VWAP with Standard Deviation Bands
//@param src Source price series (typically hlc3)
//@param vol Volume series
//@param reset_condition Condition to reset VWAP calculation
//@param num_devs Number of standard deviations for bands
//@returns [vwap, upper_band, lower_band]
vwapsd(series float src, series float vol, series bool reset_condition, simple float num_devs) =>
    if num_devs <= 0
        runtime.error("Number of deviations must be greater than 0")
    if num_devs > 5
        runtime.error("Number of deviations exceeds maximum of 5")
    
    var float sum_pv = 0.0, var float sum_vol = 0.0, var float sum_pv2 = 0.0
    float current_price = nz(src), float current_vol = nz(vol, 0.0)
    
    if reset_condition
        sum_pv := current_vol > 0.0 ? current_price * current_vol : 0.0
        sum_vol := current_vol > 0.0 ? current_vol : 0.0
        sum_pv2 := current_vol > 0.0 ? current_price * current_price * current_vol : 0.0
    else
        if current_vol > 0.0
            sum_pv += current_price * current_vol
            sum_vol += current_vol
            sum_pv2 += current_price * current_price * current_vol
    
    float vwap = sum_vol > 0.0 ? sum_pv / sum_vol : src
    float variance = sum_vol > 0.0 ? (sum_pv2 / sum_vol) - math.pow(vwap, 2) : 0.0
    float stddev = math.sqrt(math.max(0.0, variance))
    
    float upper = vwap + (num_devs * stddev)
    float lower = vwap - (num_devs * stddev)
    
    [vwap, upper, lower]

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

// Inputs
i_source = input.source(hlc3, "Source")
i_session_type = input.string("1D", "Session Reset", options=["1m", "2m", "3m", "5m", "10m", "15m", "30m", "45m", "1H", "2H", "3H", "4H", "1D", "1W", "1M", "3M", "6M", "12M", "Never"])
i_num_devs = input.float(2.0, "Standard Deviations", minval=0.1, maxval=5.0, step=0.1, tooltip="Number of standard deviations for bands")

// Calculate reset condition
reset_condition = switch i_session_type
    "1m" => ta.change(time("1")) != 0
    "2m" => ta.change(time("2")) != 0
    "3m" => ta.change(time("3")) != 0
    "5m" => ta.change(time("5")) != 0
    "10m" => ta.change(time("10")) != 0
    "15m" => ta.change(time("15")) != 0
    "30m" => ta.change(time("30")) != 0
    "45m" => ta.change(time("45")) != 0
    "1H" => ta.change(time("60")) != 0
    "2H" => ta.change(time("120")) != 0
    "3H" => ta.change(time("180")) != 0
    "4H" => ta.change(time("240")) != 0
    "1D" => ta.change(time("1D")) != 0
    "1W" => ta.change(time("1W")) != 0
    "1M" => ta.change(time("1M")) != 0
    "3M" => ta.change(time("3M")) != 0
    "6M" => ta.change(time("6M")) != 0
    "12M" => ta.change(time("12M")) != 0
    "Never" => bar_index == 0
    => false

// Calculation
[vwap, upper, lower] = vwapsd(i_source, volume, reset_condition, i_num_devs)

// Plot
plot(vwap, "VWAP", color=color.yellow, linewidth=2)
plot(upper, "Upper Band", color=color.red, linewidth=1, style=plot.style_line)
plot(lower, "Lower Band", color=color.green, linewidth=1, style=plot.style_line)

// Fill between bands
fill_color = color.new(color.gray, 90)
fill(plot(upper), plot(lower), color=fill_color, title="Band Fill")

Overview

Cumulative price-volume sums reset when the selected session interval changes, or only on the first bar when reset is set to never. Users can change the source, the reset period from one minute through twelve months, and the band width. It draws the VWAP, both bands, and a shaded fill on the price chart. It does not generate trade signals.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Volume, 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
Sourcesourcehlc3i_source
Session Resetstring1Di_session_type
Standard Deviationsfloat2.0i_num_devs
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

The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha

Indicator v5 Oscillators & momentumTrend
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup

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

VWAP Bands Template

by TradersPost
218 stars

This indicator plots a volume-weighted average price and three standard-deviation bands on the price chart. It resets the running volume-weighted totals at the selected anchor, which can be the session, week, month, quarter, or year. The source price, band mul

Indicator v6 VolumeVolatility & bands
Updated 3 months ago · None stated GitHub repository of VWAP Bands Template

LiqSpikeBounceLong Feb2026

by agutinbaigo28
147 stars

LiqSpikeBounceLong Feb2026 is an indicator designed to identify long bounce entries following high-volume liquidation cascades in bearish market contexts. It checks if price is below an exponential moving average, then detects large single-bar drops exceeding

Indicator v5 Volatility & bandsVolume
Updated 6 weeks ago · MIT GitHub repository of LiqSpikeBounceLong Feb2026

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
92 stars

This indicator plots a volume-weighted average price of the typical price on the chart and colors that line by ADX strength. It draws a standard-deviation envelope around VWAP and tints the fill green when plus DI leads and red when minus DI leads. Triangle ma

Indicator v5 TrendOscillators & momentum
Updated 8 weeks ago · Custom licence GitHub repository of Moon Dev VWAP x ADX Explosion

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