As asked for, here is the VWAP deviations in several forms, including Z-Score distance from VWAP, lower studies, and more.
Pink is VWAP and Cyan is 200 period Std Dev
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2018-2019
#
input length = 200;
def zeros = vwap -vwap[2];
def filter = reference EhlersSuperSmootherFilter(price = zeros, "cutoff length" = 0.5 * length);
def rms = Sqrt(Average(Sqr(filter), length));
def scaledFilter = filter / rms;
def alpha = 5 * AbsValue(scaledFilter) / length;
def deviationScaledMovAvg = CompoundValue(1, alpha * vwap + (1 - alpha) * deviationScaledMovAvg[1], vwap);
plot DSMA = deviationScaledMovAvg;
DSMA.SetDefaultColor(GetColor(1));
VWAP deviation at 20 period and 200 period lengths
Code:
declare lower;
input price = close;
input length = 20;
def SMA = Average(vwap[0], length);
plot DEV =(vwap/sma -1 )*100;
plot pdl = .5;
plot ndl = -.5;
plot zero = 0;
DEV.SetDefaultColor(GetColor(1));
input price2 = close;
input length2 = 200;
def SMA2 = Average(vwap[0], length2);
plot DEV2 =(vwap/SMA2 -1 )*100;
DEV2.SetDefaultColor(GetColor(2));
VWAP Z-Score
Code:
# Intraday VWAP Zscore
# Mobius
# 06.10.2019 Chat Room Request
declare lower;
def RTH = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and
GetTime() <= RegularTradingEnd(GetYYYYMMDD());
def n = if RTH and !RTH[1]
then 1
else if RTH
then n[1] + 1
else n[1];
def Avg = (fold i = 0 to n
with s
do s + getValue(close, i)) / n;
def VWAP_ = (fold ii = 0 to n
with ss
do ss + getValue(vwap, ii)) / n;
def StDev = Sqrt((fold iii = 0 to n
with sss = 0
do sss + Sqr(Avg - getValue(close, iii))) / n);
plot Zscore = (close - VWAP_) / StDev;
plot "0" = if isNaN(close) then double.nan else 0;
"0".SetDefaultColor(Color.white);
plot "1SD" = if isNaN(close) then double.nan else 1;
"1SD".SetDefaultColor(Color.Green);
plot "2SD" = if isNaN(close) then double.nan else 2;
"2SD".SetDefaultColor(Color.Green);
plot "-1SD" = if isNaN(close) then double.nan else -1;
"-1SD".SetDefaultColor(Color.Red);
plot "-2SD" = if isNaN(close) then double.nan else -2;
"-2SD".SetdefaultColor(Color.Red);
AddCloud(0, Zscore, color.red, color.green);
# End Code
Simple VWAP deviation script
Code:
declare lower;
input price = close;
input length = 20;
def vwd = Average(vwap[0], length);
plot DEV =(vwap/vwd -1 )*10;
plot pdl = .05;
plot ndl = -.05;
plot zero = 0;
Alert(DEV crosses below ndl, "", Alert.BAR, Sound.Bell);
Alert(DEV crosses above pdl, "", Alert.BAR, Sound.Bell);
DEV.SetDefaultColor(GetColor(1));
Attachments
Last edited: