Indicator · Pine Script v6 · On the chart

VWAP Basic

by shubhamtaywade82

Calculates a volume-weighted average price that resets each day, week or month and plots it on the price chart.

View on GitHub

Archived by its author

GitHub stars1on the repository
Pine versionv6current
Lines of code62
Settings8inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago31 May 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

62 lines of Pine Script v6 from indicators/agent-examples/vwap-basic-bands.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

vwap-basic-bands.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Ported from pinescript-agents/examples/simple/vwap-basic.pine for local testing in pinescripts-collections.

//@version=6
indicator("VWAP Basic [Agent Example]", "VWAP · AE", overlay=true)

anchor_period = input.string("Session", "Anchor Period", options=["Session", "Week", "Month"], group="Settings")
show_bands = input.bool(true, "Show Standard Deviation Bands", group="Display")
std_mult1 = input.float(1.0, "1st StdDev Multiplier", minval=0.1, maxval=5.0, group="Bands")
std_mult2 = input.float(2.0, "2nd StdDev Multiplier", minval=0.1, maxval=5.0, group="Bands")
vwap_color = input.color(color.blue, "VWAP Color", group="Colors")
band_color = input.color(color.gray, "Band Color", group="Colors")
bullColorInput = input.color(#089981, "Bullish Color", group="Colors")
bearColorInput = input.color(#f23645, "Bearish Color", group="Colors")

var float sum_pv = 0.0
var float sum_v = 0.0
var float sum_pv2 = 0.0

is_new_period() =>
    switch anchor_period
        "Session" => timeframe.change("1D")
        "Week" => timeframe.change("1W")
        "Month" => timeframe.change("1M")
        => false

typ_price = hlc3

if is_new_period()
    sum_pv := 0.0
    sum_v := 0.0
    sum_pv2 := 0.0

sum_pv += typ_price * volume
sum_v += volume
sum_pv2 += typ_price * typ_price * volume

vwap_value = sum_v > 0 ? sum_pv / sum_v : na
variance = sum_v > 0 and not na(vwap_value) ? (sum_pv2 / sum_v) - (vwap_value * vwap_value) : na
std_dev = not na(variance) and variance >= 0 ? math.sqrt(variance) : na

upper_band1 = not na(vwap_value) and not na(std_dev) ? vwap_value + (std_dev * std_mult1) : na
lower_band1 = not na(vwap_value) and not na(std_dev) ? vwap_value - (std_dev * std_mult1) : na
upper_band2 = not na(vwap_value) and not na(std_dev) ? vwap_value + (std_dev * std_mult2) : na
lower_band2 = not na(vwap_value) and not na(std_dev) ? vwap_value - (std_dev * std_mult2) : na

plot(vwap_value, title="VWAP", color=vwap_color, linewidth=2)

p_ub1 = plot(show_bands ? upper_band1 : na, title="Upper Band 1", color=color.new(band_color, 50), linewidth=1)
p_lb1 = plot(show_bands ? lower_band1 : na, title="Lower Band 1", color=color.new(band_color, 50), linewidth=1)
plot(show_bands ? upper_band2 : na, title="Upper Band 2", color=color.new(band_color, 70), linewidth=1)
plot(show_bands ? lower_band2 : na, title="Lower Band 2", color=color.new(band_color, 70), linewidth=1)

fill(p_ub1, p_lb1, color=color.new(band_color, 90), title="VWAP Channel")

var table info_table = table.new(position.top_right, 2, 4, bgcolor=color.new(#0b0e14, 25), border_width=1, border_color=color.new(#2a2e39, 40))
if barstate.islast
    table.cell(info_table, 0, 0, "VWAP", text_color=color.white, text_size=size.small)
    table.cell(info_table, 1, 0, str.tostring(vwap_value, "#.####"), text_color=vwap_color, text_size=size.small)
    table.cell(info_table, 0, 1, "Distance", text_color=color.white, text_size=size.small)
    dist_pct = not na(vwap_value) and vwap_value != 0 ? ((close - vwap_value) / vwap_value) * 100 : na
    table.cell(info_table, 1, 1, str.tostring(dist_pct, "#.##") + "%", text_color=close > vwap_value ? bullColorInput : bearColorInput, text_size=size.small)

Overview

Two optional standard deviation bands use adjustable multipliers, with a shaded channel between the inner pair. A small table shows the current VWAP and the percentage distance of price from it. It needs volume data to work, so symbols without volume show nothing useful.

Details

Published by

shubhamtaywade82 on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Volume, Support & resistance

Markets

Any symbol

Timeframes

M15-H1

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.

Settings

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

SettingTypeDefaultVariable
Anchor PeriodstringSessionanchor_period
Show Standard Deviation Bandsbooltrueshow_bands
1st StdDev Multiplierfloat1.0std_mult1
2nd StdDev Multiplierfloat2.0std_mult2
VWAP Colorcolorcolor.bluevwap_color
Band Colorcolorcolor.grayband_color
Bullish Colorcolor#089981bullColorInput
Bearish Colorcolor#f23645bearColorInput
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

This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur

Indicator v5 VolumeSupport & resistance
Updated 2 months ago · MIT GitHub repository of Volume Profile and Indicator by DGT

MGIC-tracker

by Allen1212
303 stars

The MGIC-tracker is a TradingView indicator that overlays ARK Invest trade records onto stock price charts. It plots buy and sell labels at the exact timestamp of each transaction, showing share volume and ETF weight. Users select a specific ETF type via setti

Indicator v4 Support & resistanceVolume
Updated 2 years ago · None stated GitHub repository of MGIC-tracker
218 stars

Comprehensive Volume Profile is an overlay indicator that calculates and plots volume distribution across specified time ranges such as daily sessions, weekly, monthly, or custom bar lengths. It identifies key structural price levels including the Point of Con

Indicator v6 VolumeSupport & resistance
Updated 3 months ago · None stated GitHub repository of Comprehensive Volume Profile

Moon Dev GEX Arrows

by moondevonyt
92 stars

This overlay indicator plots option strike walls and an optional session VWAP on the price chart for SPY or ES. It spaces major strikes by the selected instrument, draws a set number of strikes on each side, and marks wall-trap and sweep events after a cooldow

Indicator v5 Support & resistanceSessions & time
Updated 2 months ago · Custom licence GitHub repository of Moon Dev GEX Arrows

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