VWAP Deviation Scaled Moving Average for ThinkorSwim



Active member
Shows the deviation from the VWAP . Plot is aqua and VWAP is yellow.

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

Last edited:


Well-known member
If anyone can explain how this would be helpful, scaling to price with a vwap, I would certainly like to know.


Active member
@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.
Thread starter Similar threads Forum Replies Date
I Questions 5
H Indicators 8
H Indicators 0
M Questions 2
Z Questions 5