PoshTrader

Bollinger Bands Squeeze

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?
study("BB Squeeze", scale=scale.right, overlay=true)

//--- Keltner
kLength = input(20, title="Keltner Lenght")
kN = input(1.5, title="Keltner Deviation")
kUpper = sma(close,kLength) + kN*atr(kLength)
kLower = sma(close,kLength) - kN*atr(kLength)

//--- Bollinger
bbLength = input(20, title="Bollinger Length")
bbN = input(2, title="Bollinger Deviation")
bbUpper = sma(close,bbLength) + bbN*stdev(close,bbLength)
bbLower = sma(close,bbLength) - bbN*stdev(close,bbLength)

//--- BB Squeeze
squeeze = bbUpper <= kUpper and bbLower >=kLower

//--- Plots
plot(bbUpper, title="Upper Band")
plot(bbLower, title="Lower Band")

//--- Fill
a = plot(squeeze?bbUpper:na, style=linebr, color=n?na:white, title="Squeezed Upper Band")
b = plot(squeeze?bbLower:na, style=linebr, color=n?na:white, title="Squeezed Lower Band")
fill(a,b, color=yellow, transp=30, title="Squeezed Area")