// 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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Anchor Period
string
Session
anchor_period
Show Standard Deviation Bands
bool
true
show_bands
1st StdDev Multiplier
float
1.0
std_mult1
2nd StdDev Multiplier
float
2.0
std_mult2
VWAP Color
color
color.blue
vwap_color
Band Color
color
color.gray
band_color
Bullish Color
color
#089981
bullColorInput
Bearish Color
color
#f23645
bearColorInput
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.
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
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
This overlay indicator marks call and put setups from EMAs, RSI, MACD, and a SPY volume ratio. A call needs higher highs, RSI above its minimum, rising MACD, above-average proxy volume, and a rising trend EMA; a put reverses those tests. Early markers use an E
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
This indicator plots two Hull moving averages on the price chart, one of the selected price and one of close, and optionally smooths both with a Kahlman filter. It fills the space between them and marks buy and sell labels when they cross, provided scaled volu
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