• LIMITED TIME OFFER: use coupon code PRIMEDAY (case sensitive) at checkout to save $50 off VIP membership (down to $149 / year). Valid through Tuesday 6/22. Biggest discount this year!

VWAP Deviation Scaled Moving Average for ThinkorSwim

horserider

Well-known member
VIP
Shows the deviation from the VWAP . Plot is aqua and VWAP is yellow.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2018-2019
#Original code TD Ameritrade IP Company, Inc. (c) 2018-2019 for Deviation Scaled Moving Average altered to be Deviation Scaled Moving Average #of VWAP by Horserider.

input length = 40;

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));


4EUm8yi.png
 
Last edited:

markos

Well-known member
VIP
If anyone can explain how this would be helpful, scaling to price with a vwap, please let us know.
 
Last edited:

horserider

Well-known member
VIP
@john3 No idea. That was the input length in the ToS Deviation study. I just modified it to show deviation from VWAP as someone was looking for something like it. Since VWAP is a moving average and follows price I am not even seeing any value in this. Better to just stick with the standard ToS Deviation Scaled Moving Average of price. As with any moving average the larger the input length the flatter and the larger the deviation from price can become. Adjust it to fit what you want.
 

Similar threads

Top