Indicator · Pine Script v5 · On the chart

Volume Weighted Average Price

by TWODS-CAPITAL

This indicator plots a volume-weighted average price on the price chart.

View on GitHub

Repaints

GitHub stars37on the repository
Pine versionv5runs as is
Lines of code78
Settings6inputs
LicenceMIT
Last update3 years ago10 Feb 2023

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

78 lines of Pine Script v5 from Technical-Indicators/Technical Indicators are Here🤩/Volume-Weighted-Average-Price.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

Volume-Weighted-Average-Price.pine
//@version=5
indicator(title="Volume Weighted Average Price", shorttitle="VWAP", overlay=true, timeframe="", timeframe_gaps=true)

var cumVol = 0.
cumVol += nz(volume)
if barstate.islast and cumVol == 0
    runtime.error("No volume is provided by the data vendor.")
    
computeVWAP(src, isNewPeriod, stDevMultiplier) =>
    var float sumSrcVol = na
    var float sumVol = na
    var float sumSrcSrcVol = na

    sumSrcVol := isNewPeriod ? src * volume : src * volume + sumSrcVol[1]
    sumVol := isNewPeriod ? volume : volume + sumVol[1]
    // sumSrcSrcVol calculates the dividend of the equation that is later used to calculate the standard deviation
    sumSrcSrcVol := isNewPeriod ? volume * math.pow(src, 2) : volume * math.pow(src, 2) + sumSrcSrcVol[1]

    _vwap = sumSrcVol / sumVol
    variance = sumSrcSrcVol / sumVol - math.pow(_vwap, 2)
    variance := variance < 0 ? 0 : variance
    stDev = math.sqrt(variance)

    lowerBand = _vwap - stDev * stDevMultiplier
    upperBand = _vwap + stDev * stDevMultiplier

    [_vwap, lowerBand, upperBand]

hideonDWM = input(false, title="Hide VWAP on 1D or Above", group="VWAP Settings")
var anchor = input.string(defval = "Session", title="Anchor Period",
 options=["Session", "Week", "Month", "Quarter", "Year", "Decade", "Century", "Earnings", "Dividends", "Splits"], group="VWAP Settings")
src = input(title = "Source", defval = hlc3, group="VWAP Settings")
offset = input(0, title="Offset", group="VWAP Settings")

showBands = input(true, title="Calculate Bands", group="Standard Deviation Bands Settings")
stdevMult = input(1.0, title="Bands Multiplier", group="Standard Deviation Bands Settings")

timeChange(period) =>
    ta.change(time(period))

new_earnings = request.earnings(syminfo.tickerid, earnings.actual, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)
new_dividends = request.dividends(syminfo.tickerid, dividends.gross, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)
new_split = request.splits(syminfo.tickerid, splits.denominator, barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)

isNewPeriod = switch anchor
    "Earnings" => not na(new_earnings)
    "Dividends" => not na(new_dividends)
    "Splits" => not na(new_split)
    "Session" => timeChange("D")
    "Week" => timeChange("W")
    "Month" => timeChange("M")
    "Quarter" => timeChange("3M")
    "Year" => timeChange("12M")
    "Decade" => timeChange("12M") and year % 10 == 0
    "Century" => timeChange("12M") and year % 100 == 0
    => false

isEsdAnchor = anchor == "Earnings" or anchor == "Dividends" or anchor == "Splits"
if na(src[1]) and not isEsdAnchor
    isNewPeriod := true

float vwapValue = na
float std = na
float upperBandValue = na
float lowerBandValue = na

if not (hideonDWM and timeframe.isdwm)
    [_vwap, bottom, top] = computeVWAP(src, isNewPeriod, stdevMult)
    vwapValue := _vwap
    upperBandValue := showBands ? top : na
    lowerBandValue := showBands ? bottom : na

plot(vwapValue, title="VWAP", color=#2962FF, offset=offset)

upperBand = plot(upperBandValue, title="Upper Band", color=color.green, offset=offset)
lowerBand = plot(lowerBandValue, title="Lower Band", color=color.green, offset=offset)

fill(upperBand, lowerBand, title="Bands Fill", color= showBands ? color.new(color.green, 95) : na)

Overview

Volume Weighted Average Price accumulates the selected source, defaulting to the average of high, low, and close, against volume and resets when the chosen anchor begins. Anchors include session, week, month, quarter, year, decade, century, and corporate events such as earnings, dividends, and splits. Optional bands sit a chosen number of standard deviations above and below the average. Users can offset the plots and hide the lines on daily charts and higher. It stops with an error when the symbol has no volume.

Details

Published by

TWODS-CAPITAL on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Volume, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Settings

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

SettingTypeDefaultVariable
Hide VWAP on 1D or AboveboolfalsehideonDWM
Anchor PeriodstringSessionanchor
Sourcesourcehlc3src
Offsetint0offset
Calculate BandsbooltrueshowBands
Bands Multiplierfloat1.0stdevMult
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

VWAP Bands

by mihakralj
99 stars

This indicator plots a volume-weighted average price on the price chart and resets the calculation when the selected session changes. It builds first and second standard-deviation bands from a volume-weighted variance of the chosen source, which defaults to th

Indicator v6 VolumeVolatility & bands
Updated 4 weeks ago · Apache-2.0 GitHub repository of VWAP Bands

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