Indicator · Pine Script v6 · On the chart

VWAP Bands

by mihakralj

This indicator plots a volume-weighted average price on the price chart and resets the calculation when the selected session changes.

View on GitHub

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

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

vwapbands.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("VWAP Bands (VWAPBANDS)", "VWAPBANDS", overlay=true)

//@function Calculates VWAP Bands with standard deviation bands
//@param src Source price series (typically hlc3)
//@param vol Volume series
//@param reset_condition Condition to reset VWAP calculation
//@param multiplier Standard deviation multiplier for bands
//@returns [vwap_value, upper_band1, lower_band1, upper_band2, lower_band2, stdev] VWAP and band values
//@optimized for performance and dirty data
vwapbands(series float src, series float vol, series bool reset_condition, series float multiplier) =>
    var float sum_pv = 0.0, var float sum_vol = 0.0, var float sum_pv2 = 0.0, var int count = 0
    float current_price = nz(src), float current_vol = nz(vol, 0.0)
    if reset_condition
        if current_vol > 0.0
            sum_pv := current_price * current_vol
            sum_vol := current_vol
            sum_pv2 := current_price * current_price * current_vol
            count := 1
        else
            sum_pv := 0.0, sum_vol := 0.0, sum_pv2 := 0.0, count := 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
            count += 1
    float vwap_val = sum_vol > 0.0 ? sum_pv / sum_vol : src
    float variance = 0.0
    if sum_vol > 0.0 and count > 1
        mean_p2 = sum_pv2 / sum_vol
        vwap_squared = vwap_val * vwap_val
        variance := math.max(0.0, mean_p2 - vwap_squared)
    float stdev = math.sqrt(variance)
    float upper1 = vwap_val + multiplier * stdev
    float lower1 = vwap_val - multiplier * stdev
    float upper2 = vwap_val + 2.0 * multiplier * stdev
    float lower2 = vwap_val - 2.0 * multiplier * stdev
    [vwap_val, upper1, lower1, upper2, lower2, stdev]

// ---------- 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_multiplier = input.float(1.0, "Standard Deviation Multiplier", minval=0.1, step=0.1)
i_show_bands2 = input.bool(true, "Show 2nd Standard Deviation 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_value, upper_band1, lower_band1, upper_band2, lower_band2, stdev] = vwapbands(i_source, volume, reset_condition, i_multiplier)

// Colors
vwap_color = color.yellow
band1_color = color.blue
band2_color = color.purple
fill_color1 = color.blue
fill_color2 = color.purple

// Plot
p_vwap = plot(vwap_value, "VWAP", color=color.yellow, linewidth=2)
p_upper1 = plot(upper_band1, "Upper Band 1σ", color=color.yellow, linewidth=2)
p_lower1 = plot(lower_band1, "Lower Band 1σ", color=color.yellow, linewidth=2)
p_upper2 = plot(i_show_bands2 ? upper_band2 : na, "Upper Band 2σ", color=color.yellow, linewidth=2)
p_lower2 = plot(i_show_bands2 ? lower_band2 : na, "Lower Band 2σ", color=color.yellow, linewidth=2)
fill(p_upper1, p_lower1, color=color.new(color.blue, 90), title="1σ Band Fill")
fill(p_upper2, p_upper1, color=i_show_bands2 ? color.new(color.purple, 90) : na, title="Upper 2σ Fill")
fill(p_lower1, p_lower2, color=i_show_bands2 ? color.new(color.purple, 90) : na, title="Lower 2σ Fill")

Overview

VWAP Bands builds first and second standard-deviation bands from a volume-weighted variance of the chosen source, which defaults to the average of high, low, and close. The session input offers resets from one minute through twelve months, or never. The multiplier scales both band distances, and a switch can hide the outer bands. It does not generate entries or exits.

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 Deviation Multiplierfloat1.0i_multiplier
Show 2nd Standard Deviation Bandsbooltruei_show_bands2
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