 # Variable Moving Average Bands [LazyBear]

9149 views
VMA Bands are ATR bands with VMA as its centre. For a description of options, refer to my VMA post:
I have moved VMA calculation in to a separate function. Feel free to use calc_vma() in your scripts. For more MA calculation function ( KAMA , VIDYA and others), refer to my complete list of indicators below.

Wish you all a very prosperous New year. Hope these indicators make you all more money this year too :)

List of my other indicators:
- Chart:
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Want to use this script on a chart?
//
// @author LazyBear
// List of all my indicators:
//
study(title="Variable Moving Average Bands [LazyBear]", shorttitle="VMABANDS_LB", overlay=true)
src=close
l=input(6, title="VMA Length")
bm=input(1.5, title="Bands Multipler")
std=input(false, title="Show Trend Direction")
bc=input(false, title="Color bars based on Trend")
calc_vma(src, l) =>
k = 1.0/l
pdm = max((src - src), 0)
mdm = max((src - src), 0)
pdmS = ((1 - k)*nz(pdmS) + k*pdm)
mdmS = ((1 - k)*nz(mdmS) + k*mdm)
s = pdmS + mdmS
pdi = pdmS/s
mdi = mdmS/s
pdiS = ((1 - k)*nz(pdiS) + k*pdi)
mdiS = ((1 - k)*nz(mdiS) + k*mdi)
d = abs(pdiS - mdiS)
s1 = pdiS + mdiS
iS = ((1 - k)*nz(iS) + k*d/s1)
hhv = highest(iS, l)
llv = lowest(iS, l)
d1 = hhv - llv
vI = (iS - llv)/d1
vma=(1 - k*vI)*nz(vma) + k*vI*src
vma

vma=calc_vma(src, l)
o=bm*atr(l)
uband=vma+o
lband=vma-o
vmaC=(vma > vma) ? green : (vma<vma) ? red : (vma==vma) ? blue : black
plot(vma, color=std?vmaC:black, linewidth=3, title="VMA")
ubx=plot(uband, color=gray, linewidth=2, title="UpperBand")
lbx=plot(lband, color=gray, linewidth=2, title="LowerBand")
fill(ubx,lbx, color=black, transp=95)
barcolor(bc?vmaC:na)
List of my free indicators: http://bit.ly/1LQaPK8
List of my indicators at Appstore: http://blog.tradingview.com/?p=970 Very nice, indebted to yours, ucsgears and ChrisMoody's scripts.
Great work, as usual.
Have you used these, or just coding them for fun?  