UDAY_C_Santhakumar

Bollinger Bands %B Bollinger Bands - Version 2

Thanks to Chris Moody for his touch

List of All my Indicators - www.tradingview.com/p/stocks/?sort=recen...

Uday C Santhakumar
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.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
//Updated by ChrisMoody on 8/14/2014 --  Original Code From ucsgears
study(title = "Bollinger Bands %B Bollinger Bands", shorttitle = "BB %B BB")
source = close
length = input(20, minval=1), mult = input(2.0, minval=0.001, maxval=50)
basis = sma(source, length)
dev = mult * stdev(source, length)
upper = basis + dev
lower = basis - dev
bbr = (source - lower)/(upper - lower)
//plot(bbr, color=teal)
 
basisa = sma(bbr, length)
deva = mult * stdev(bbr, length)
uppera = basisa + deva
lowera = basisa - deva
 
//Added This
aboveUp = bbr > uppera ? 1 : 0
belowDn = bbr < lowera ? 1 : 0
plotchar(aboveUp, title="i", char='S', location=location.top, color=red, transp=0, offset=0)
plotchar(belowDn, title="i", char='B', location=location.bottom, color=green, transp=0, offset=0)
 
//Added in BackGround Hilighting
noTrade = aboveUp == 0 and belowDn == 0
bgcolor(noTrade ? gray : na, transp=50)
bgcolor(aboveUp ? red : na, transp=60)
bgcolor(belowDn ? green : na, transp=60)
 
//Added This
col = bbr < lowera ? lime : bbr > uppera ? red : teal
 
//Changed your plot fills from Midline to top of band...and midline to lower band.
p1 = plot(basisa, color=silver, linewidth=0)
p2 = plot(uppera, color=red, linewidth=2)
p3 = plot(lowera, color=green, linewidth=2)
fill(p1, p2, color=red, transp = 70)
fill(p1, p3, color=green, transp = 70)
plot(bbr, color= col, style=linebr, linewidth=3)