Volatility
Bollinger Squeeze
Shades the chart while both Bollinger bands sit inside an ATR channel drawn from the same basis, which is the state people call a squeeze, and marks the bar the bands push back outside it.
indicator
//@version=6
indicator("Bollinger Squeeze", "Squeeze", overlay = true)
length = input.int(20, "Length", minval = 2, group = "Settings")
bbMult = input.float(2.0, "Bollinger deviations", minval = 0.1, step = 0.1, group = "Settings")
kcMult = input.float(1.5, "ATR multiplier", minval = 0.1, step = 0.1, group = "Settings")
tightCol = input.color(#EF5350, "In squeeze", group = "Style")
looseCol = input.color(#26A69A, "Released", group = "Style")
bandCol = input.color(#787B86, "Bands", group = "Style")
[basis, bbUpper, bbLower] = ta.bb(close, length, bbMult)
atr = ta.atr(length)
kcUpper = basis + atr * kcMult
kcLower = basis - atr * kcMult
squeezed = bbUpper < kcUpper and bbLower > kcLower
started = squeezed and not squeezed[1]
released = not squeezed and squeezed[1]
pUpper = plot(bbUpper, "Bollinger upper", color = bandCol)
pLower = plot(bbLower, "Bollinger lower", color = bandCol)
plot(kcUpper, "ATR channel upper", color = color.new(bandCol, 55))
plot(kcLower, "ATR channel lower", color = color.new(bandCol, 55))
fill(pUpper, pLower, color = squeezed ? color.new(tightCol, 88) : color.new(looseCol, 94), title = "Envelope")
plotshape(started, "Squeeze started", location = location.abovebar, style = shape.circle, color = tightCol, size = size.tiny)
plotshape(released, "Squeeze released", location = location.belowbar, style = shape.circle, color = looseCol, size = size.tiny)
alertcondition(started, "Squeeze started", "The Bollinger bands have moved inside the ATR channel")
alertcondition(released, "Squeeze released", "The Bollinger bands have expanded back outside the ATR channel")
This runs in TradingView, not here
Pine Script only executes inside TradingView. Paste the source into the Pine Editor and add it to a chart to see it plotted.
What it will not do
- A squeeze says volatility is compressed. It says nothing about which way the expansion goes when it comes.
- Compression can persist for a long time and can also release straight back into more compression, so the release bar is not a commitment to anything.
- Both measures look backwards over the same window, so the whole comparison is a statement about bars that have already closed.
- Drawing both envelopes from one basis makes them comparable but ties the result to that basis. Other published versions use separate ones and mark different bars.
Written from this description
Compare Bollinger bands against a Keltner style ATR channel built on the same basis. Highlight the bars where the Bollinger bands are entirely inside the channel, and mark where the squeeze starts and where it ends.
Educational only, not financial advice. The maths is simple arithmetic on the numbers you enter; it knows nothing about your broker, fees, slippage or the market. Something wrong with it? Say so in Site Feedback.