Professional Documents
Culture Documents
VWAP
VWAP
// Shows the Daily, Weekly, Monthly, Quarterly, and Yearly VWAP. Also
// shows the previous closing VWAP, which is usually very near the
// HLC3 standard pivot for the previous time frame. i.e. The previous
// daily VWAP closing price is usually near the current Daily Pivot.
study("VWAP", overlay = true)
rez1 = iff(bands == "1. Day", "D", iff(bands == "2. Week", "W", iff(bands == "3.
Month", "M", iff(bands == "4. Quarter", "3M", "12M"))))
newSessionD = iff(change(startD), 1, 0)
newSessionW = iff(change(startW), 1, 0)
newSessionM = iff(change(startM), 1, 0)
newSessionQ = iff(change(startQ), 1, 0)
newSessionY = iff(change(startY), 1, 0)
getVWAP(newSession) =>
p = hlc3 * volume
p := newSession ? hlc3 * volume : p[1] + hlc3 * volume
vol = 0.0
vol := newSession ? volume : vol[1] + volume
v = p / vol
Sn = 0.0
Sn := newSession ? 0 : Sn[1] + volume * (hlc3 - v[1]) * (hlc3 - v)
std = sqrt(Sn / vol)
[v, std]
dColor = #008000FF
wColor = #008080DD
mColor = #808000FF
qColor = #801010FF
yColor = #091580FF
s1up = plot(islastSR and showStd ? v + std1 * s : na, title = "VWAP - STDEV 1",
color = #00FFFFDD, style = plot.style_line, linewidth = 1)
s1dn = plot(islastSR and showStd ? v - std1 * s : na, title = "VWAP - STDEV 1",
color = #00FFFFDD, style = plot.style_line, linewidth = 1)
s2up = plot(islastSR and showStd ? v + std2 * s : na, title = "VWAP - STDEV 2",
color = #FF00FFDD, style = plot.style_line, linewidth = 1)
s2dn = plot(islastSR and showStd ? v - std2 * s : na, title = "VWAP - STDEV 2",
color = #FF00FFDD, style = plot.style_line, linewidth = 1)
s3up = plot(islastSR and showStd ? v + std3 * s : na, title = "VWAP - STDEV 3",
color = #CCCCCCDD, style = plot.style_line, linewidth = 1)
s3dn = plot(islastSR and showStd ? v - std3 * s : na, title = "VWAP - STDEV 3",
color = #CCCCCCDD, style = plot.style_line, linewidth = 1)
plot(islastSR and showPrev ? pvD : na, title = "Previous VWAP - Daily", color = pvD
!= pvD[1] ? na : color.red, style = plot.style_line, transp = 10, linewidth = 1)
plot(islastSR and showPrev ? pvW : na, title = "Previous VWAP - Weekly", color =
#40E20099, style = plot.style_cross, transp = 10, linewidth = 2, display =
display.none)
plot(islastSR and showPrev ? pvM : na, title = "Previous VWAP - Monthly", color =
#80C60099, style = plot.style_cross, transp = 10, linewidth = 3, display =
display.none)
plot(islastSR and showPrev ? pvQ : na, title = "Previous VWAP - Quarterly", color =
#BFA90099, style = plot.style_cross, transp = 10, linewidth = 4, display =
display.none)
plot(islastSR and showPrev ? pvY : na, title = "Previous VWAP - Yearly", color =
#FF8C0099, style = plot.style_cross, transp = 10, linewidth = 4, display =
display.none)
// Labels
label.set_x(l, x)
label.set_y(l, price)
label.set_style(l, isUp ? label.style_labeldown : label.style_labelup)
label.set_text(l, prefix + "\n" + tostring(p))
// end