Chande Variable Moving Average Indicator for ThinkorSwim


Well-known member
TOS has built in variable MA , however what I wanted is flatter ma in case of chop. One from tradingview by lazybear fit the bill. its adaption for TOS
#added coloration
# formula from lazy bear #

input price = close;
input length = 13;

script VMA
input price=close;
input length=13;
def k = 1.0/length;
def src=if isnan(price[1]) then 0 else price;
def pdm = max((src - src[1]), 0);
def mdm = max((src[1] - src), 0);
def pdmS = if isnan(pdms[1]) then k*pdm else ((1 - k)*(pdmS[1]) + k*pdm);
def mdmS = if isnan(mdms[1]) then k*mdm else ((1 - k)*(mdmS[1]) + k*mdm);
def s = pdmS + mdmS;
def pdi = pdmS/s; def mdi = mdmS/s;
def pdiS = if isnan(pdis[1]) then k*pdi else ((1 - k)*(pdiS[1]) + k*pdi);
def mdiS = if isnan(mdis[1]) then k*mdi else ((1 - k)*(mdiS[1]) + k*mdi);
def d = absvalue(pdiS - mdiS);
def s1 = pdiS + mdiS;
def iS = if isnan(is[1]) then  k*d/s1 else ((1 - k)*(iS[1]) + k*d/s1);
def hhv = highest(iS, length);
def llv = lowest(iS, length) ;
def d1 = hhv - llv;
def vI = (iS - llv)/d1;
def val= if isnan(val[1]) then k*vI*src else (1 - k*vI)*(val[1]) + k*vI*src;
plot vma=val;

plot pVMA = vma(price,length);
pVMA.assignValueColor(if pvma>pvma[1] then
         else if   pvma<pvma[1] then
         else color.gray);

Fixed some bugs
Last edited:


Well-known member
@skynetgen if you so choose, put Chande in front of the VMA Title. Otherwise others may think it's just another one of "those" and not open the thread. This is a great indicator. Thank you for translating...


Well-known member
2019 Donor
@skynetgen this looks great. need to try. so in the particular configuration, blue = long, yellow/orange = short, and gray is neutral?

could be a great chop reducer with a 9 length/1 minute.

Similar threads