Indicator · Pine Script v6 · Own pane

Bollinger Band Squeeze Detector

by shubhamtaywade82

Detects a volatility squeeze when the Bollinger Bands sit inside the Keltner Channel, and shows it in a separate pane as a column state.

View on GitHub

Archived by its author

GitHub stars1on the repository
Pine versionv6current
Lines of code64
Settings11inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago31 May 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

64 lines of Pine Script v6 from indicators/agent-examples/bollinger-squeeze-detector.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

bollinger-squeeze-detector.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Ported from pinescript-agents/examples/simple/bollinger-squeeze.pine for local testing in pinescripts-collections.

//@version=6
indicator("Bollinger Band Squeeze Detector [Agent Example]", shorttitle="BBSqzAE", overlay=false, scale=scale.right)

bbLength = input.int(20, "BB Length", minval=1, group="Bollinger Bands")
bbMult = input.float(2.0, "BB Multiplier", minval=0.1, step=0.1, group="Bollinger Bands")

kcLength = input.int(20, "KC Length", minval=1, group="Keltner Channels")
kcMult = input.float(1.5, "KC Multiplier", minval=0.1, step=0.1, group="Keltner Channels")

showMomentum = input.bool(true, "Show Momentum", group="Display")
normalizeMomentum = input.bool(true, "Normalize Momentum (ATR)", group="Display")
momentumClamp = input.float(3.0, "Momentum Clamp", minval=0.5, step=0.5, group="Display")
showSqueezeCount = input.bool(true, "Show Squeeze Count", group="Display")
bullColorInput = input.color(#089981, "Bullish Color", group="Visuals")
bearColorInput = input.color(#f23645, "Bearish Color", group="Visuals")
neutralColorInput = input.color(color.new(#2a2e39, 0), "Neutral Color", group="Visuals")

basis = ta.sma(close, bbLength)
dev = bbMult * ta.stdev(close, bbLength)
bbUpper = basis + dev
bbLower = basis - dev

kcMA = ta.ema(close, kcLength)
kcRange = ta.atr(kcLength)
kcUpper = kcMA + kcRange * kcMult
kcLower = kcMA - kcRange * kcMult

squeeze = bbUpper < kcUpper and bbLower > kcLower
noSqueeze = bbUpper > kcUpper or bbLower < kcLower

donchianMid = (ta.highest(high, kcLength) + ta.lowest(low, kcLength)) / 2
momentum = close - donchianMid

var int squeezeCount = 0
squeezeCount := squeeze ? squeezeCount + 1 : 0

stateValue = squeeze ? 1.0 : -1.0
stateColor = squeeze ? color.new(bearColorInput, 70) : color.new(bullColorInput, 70)
plot(stateValue, "Squeeze State", color=stateColor, style=plot.style_columns, linewidth=1)

momUpStrong = momentum > 0 and momentum > momentum[1]
momDnStrong = momentum < 0 and momentum < momentum[1]
momentumColor = momentum > 0 ? (momUpStrong ? color.new(bullColorInput, 0) : color.new(bullColorInput, 50)) : (momDnStrong ? color.new(bearColorInput, 0) : color.new(bearColorInput, 50))
atrNorm = ta.atr(kcLength)
momentumBase = normalizeMomentum and atrNorm > 0 ? momentum / atrNorm : momentum
momentumCapped = math.max(-momentumClamp, math.min(momentumClamp, momentumBase))
plot(showMomentum ? momentumCapped : na, "Momentum", momentumColor, style=plot.style_histogram, linewidth=3)

hline(0, "Zero", color=color.new(neutralColorInput, 50), linestyle=hline.style_dotted)

var table infoTable = table.new(position.top_right, 2, 2, bgcolor=color.new(#0b0e14, 25), border_color=color.new(neutralColorInput, 70))
if showSqueezeCount and barstate.islast
    table.cell(infoTable, 0, 0, "Status", text_color=color.white, text_size=size.small)
    table.cell(infoTable, 1, 0, squeeze ? "SQUEEZE" : "NO SQUEEZE", text_color=squeeze ? bearColorInput : bullColorInput, text_size=size.small)
    if squeeze
        table.cell(infoTable, 0, 1, "Duration", text_color=color.white, text_size=size.small)
        table.cell(infoTable, 1, 1, str.tostring(squeezeCount) + " bars", text_color=color.yellow, text_size=size.small)

alertcondition(squeeze and not squeeze[1], "Squeeze Start", "Bollinger Squeeze Started")
alertcondition(noSqueeze and not noSqueeze[1], "Squeeze Release", "Bollinger Squeeze Released - Potential Breakout")
alertcondition(squeeze and squeezeCount == 10, "Extended Squeeze", "Squeeze lasting 10+ bars - Major move likely")

Overview

A momentum histogram measures close against the Donchian midline, optionally normalised by ATR and clamped. A small table reports squeeze status and duration in bars, and alerts fire when a squeeze starts or releases. Lengths and multipliers for both bands are adjustable.

Details

Published by

shubhamtaywade82 on GitHub

Draws

Separate pane below the chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
BB Lengthint20bbLength
BB Multiplierfloat2.0bbMult
KC Lengthint20kcLength
KC Multiplierfloat1.5kcMult
Show MomentumbooltrueshowMomentum
Normalize Momentum (ATR)booltruenormalizeMomentum
Momentum Clampfloat3.0momentumClamp
Show Squeeze CountbooltrueshowSqueezeCount
Bullish Colorcolor#089981bullColorInput
Bearish Colorcolor#f23645bearColorInput
Neutral Colorcolorcolor.new(#2a2e39, 0)neutralColorInput
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

TTM Squeeze

by Alorse
330 stars

This indicator plots a TTM Squeeze momentum oscillator in a separate pane. It compares a Bollinger Band offset to a Keltner Channel offset and marks the zero line white when the difference is non-negative and black when the bands are inside the channel. A line

Indicator v5 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of TTM Squeeze

Function - Logistic Equation

by ricardosantos79
261 stars

Calculates dynamic modeling values by applying a mathematical logistic differential equation to price change over a specified lookback length. It measures price momentum relative to the recent high-low price range. The script plots positive and negative logist

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 years ago · None stated GitHub repository of Function - Logistic Equation
228 stars

This indicator detects a Bollinger Band squeeze when the bands sit inside Keltner Channels, marking low volatility. It plots red dots during a squeeze and green dots when the bands are outside, in a separate pane. An optional histogram shows momentum as the cl

Indicator v6 Volatility & bandsOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Bollinger Band Squeeze Detector

MACD-V

by harryguiacorn
220 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V
147 stars

This indicator generates trade entry signals and target levels optimized for 1-hour timeframes, designed for external signal extraction. It calculates 7-period and 16-period EMAs alongside 10-period RSI and ATR filters. Long signals occur when the fast EMA cro

Indicator v5 TrendOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of Signal Strategy 100 Candles of 1H Timeframe

Bubbles Indicator

by capissimo
114 stars

The Bubbles Indicator measures volatility squeezes and expansion bursts using Bollinger Bands combined with a sinusoid oscillator and RSI divergence. It processes price data through scaled Bollinger Bands to highlight volatility changes while confirming trend

Indicator v4 Volatility & bandsOscillators & momentum Repaints
Updated 1 year ago · None stated GitHub repository of Bubbles Indicator

More Volatility & bands scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers