# Chande Variable Moving Average Indicator for ThinkorSwim

S

#### skynetgen

##### Active member
Warehouse
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.

Code:
Code:
``````#added coloration
# formula from lazy bear #https://www.tradingview.com/script/HT99VkZb-Variable-Moving-Average-Bands-LazyBear/

input price = close;
input length = 13;

script VMA
{
input price=close;
input length=13;
def k = 1.0/length;
def src=if isnan(price) then 0 else price;
def pdm = max((src - src), 0);
def mdm = max((src - src), 0);
def pdmS = if isnan(pdms) then k*pdm else ((1 - k)*(pdmS) + k*pdm);
def mdmS = if isnan(mdms) then k*mdm else ((1 - k)*(mdmS) + k*mdm);
def s = pdmS + mdmS;
def pdi = pdmS/s; def mdi = mdmS/s;
def pdiS = if isnan(pdis) then k*pdi else ((1 - k)*(pdiS) + k*pdi);
def mdiS = if isnan(mdis) then k*mdi else ((1 - k)*(mdiS) + k*mdi);
def d = absvalue(pdiS - mdiS);
def s1 = pdiS + mdiS;
def iS = if isnan(is) then  k*d/s1 else ((1 - k)*(iS) + 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) then k*vI*src else (1 - k*vI)*(val) + k*vI*src;
plot vma=val;
};

plot pVMA = vma(price,length);
pVMA.assignValueColor(if pvma>pvma then color.blue
else if   pvma<pvma then color.orange
else color.gray);
pvma.setlineWeight(3);``````
Fixed some bugs

Last edited:
• BenTen, markos and gjervis #### markos

##### Well-known member
VIP
Warehouse
@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...

S

#### skynetgen

##### Active member
Warehouse
Oh also there is great article about chande vma:

• BenTen and markos