VWAP Deviation Scaled Moving Average for ThinkorSwim

horserider

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

 
Last edited:
markos

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:
J

john3

Active member
2019 Donor
Any idea why 40 MA has been chosen? Thank you.
 
horserider

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.
 
A

Abdul1995

New member
Hello @horserider
Is there a way to add pivots that show the crossovers? It would really help me out.
Thanks :)
 

Similar threads

Top