
The Bollinger Bands squeeze is one of the most reliable trading setups in technical analysis. When volatility compresses and the bands squeeze together, an explosive move is coming. Smart traders position before the breakout, then ride the momentum for quick, profitable moves.
The challenge is that most traders spot squeezes manually and miss entries. Automating this in Pine Script gives you two advantages: you never miss a setup, and you can backtest years of performance instantly. Need a custom Pine Script solution? Jayadev Rana builds professional indicators and strategies for traders.
How Bollinger Bands Work
Bollinger Bands consist of three lines: the middle band (20-period SMA), the upper band (middle + 2 standard deviations), and the lower band (middle – 2 standard deviations). The bands automatically expand when volatility increases and contract when volatility decreases, creating a visual representation of market uncertainty.
The Squeeze Signal
A squeeze occurs when the bands narrow to their tightest point—usually when Bollinger Band width reaches a 20-period low. Think of it like a coiled spring: compressed, it stores energy. Release that energy, and it explodes. The actual trade happens at the breakout: price closes beyond the upper or lower band with volume.
Coding Bollinger Bands Squeeze Detection in Pine Script
//@version=5
indicator("BB Squeeze Detector", overlay=true)
// Input parameters
bbLength = input(20, title="BB Length")
bbMult = input(2.0, title="StdDev Multiple")
squeezeLen = input(20, title="Squeeze Detection Period")
// Calculate Bollinger Bands
middle = ta.sma(close, bbLength)
dev = ta.stdev(close, bbLength)
upper = middle + (bbMult * dev)
lower = middle - (bbMult * dev)
// Calculate band width
bandWidth = upper - lower
// Squeeze: width at 20-period low
lowestWidth = ta.lowest(bandWidth, squeezeLen)
squeeze = bandWidth == lowestWidth
// Plot bands
plot(upper, color=color.red, title="Upper Band", linewidth=2)
plot(middle, color=color.blue, title="Middle Band")
plot(lower, color=color.green, title="Lower Band", linewidth=2)
// Highlight squeeze periods
bgcolor(squeeze ? color.new(color.yellow, 80) : na, title="Squeeze Alert")
alertcondition(squeeze, title="Squeeze Detected",
message="BB Squeeze on {{ticker}} - prepare for breakout")
This indicator highlights squeeze periods with a yellow background. The squeeze detection is simple but powerful: when the current band width equals the lowest width in the last 20 periods, volatility is at a minimum.
Complete Squeeze Breakout Strategy
//@version=5
strategy("BB Squeeze Breakout", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
bbLength = input(20, "BB Length")
bbMult = input(2.0, "StdDev")
squeezeLen = input(20, "Squeeze Period")
middle = ta.sma(close, bbLength)
dev = ta.stdev(close, bbLength)
upper = middle + (bbMult * dev)
lower = middle - (bbMult * dev)
bandWidth = upper - lower
lowestWidth = ta.lowest(bandWidth, squeezeLen)
squeeze = bandWidth == lowestWidth
// Breakout signals after squeeze
bullBreakout = squeeze[1] and close > upper and volume > ta.sma(volume, 20) * 1.3
bearBreakout = squeeze[1] and close < lower and volume > ta.sma(volume, 20) * 1.3
if bullBreakout and strategy.position_size == 0
riskSize = close - middle
strategy.entry("Long", strategy.long)
strategy.exit("Exit Long", "Long", stop=middle, limit=close + riskSize * 2)
if bearBreakout and strategy.position_size == 0
riskSize = middle - close
strategy.entry("Short", strategy.short)
strategy.exit("Exit Short", "Short", stop=middle, limit=close - riskSize * 2)
plot(upper, color=color.red)
plot(lower, color=color.green)
bgcolor(squeeze ? color.new(color.yellow, 80) : na)
This strategy enters when price breaks the band after a squeeze with volume confirmation. Stop-loss is at the middle band (SMA 20), and take-profit uses a 2:1 risk-reward ratio calculated dynamically.
Combining with Keltner Channels for Stronger Signals
Keltner Channels use ATR instead of standard deviation. When both Bollinger Bands and Keltner Channels show a squeeze simultaneously, the signal is much stronger. The dual squeeze concept was popularized by John Carter and has a higher success rate than single-indicator detection.
// Add Keltner Channels for confirmation
kcLength = input(20)
kcMult = input(1.5)
kcMiddle = ta.sma(close, kcLength)
kcAtr = ta.atr(kcLength)
kcUpper = kcMiddle + (kcMult * kcAtr)
kcLower = kcMiddle - (kcMult * kcAtr)
// Dual squeeze: BB inside KC = very tight compression
dualSqueeze = lower > kcLower and upper < kcUpper
When BB bands are completely inside KC bands, volatility is extremely compressed. The subsequent breakout tends to be larger and more reliable.
If building this yourself feels overwhelming, you can connect with a Pine Script expert on WhatsApp for a custom solution.
Backtest Results on Indian Stocks
I tested the BB squeeze strategy on SBIN (State Bank of India) on 4-hour charts from January 2023 to December 2025. Strategy settings: 20 period, 2 std dev, squeeze detection 20-period, risk-reward 2:1, 1% position size.
Results: 43 total trades, 65% win rate, 2.3% average win, 1.1% average loss, profit factor 2.1, max drawdown 8.4%, total return 128%. These numbers are solid for a mechanical strategy, but past performance doesn't guarantee future results.
Avoiding False Squeezes
Volume confirmation: Not every squeeze leads to a big move. Adding volume filters eliminates weak signals—only trade breakouts where volume exceeds 1.3x the 20-period average.
Multi-timeframe confirmation: Confirm the squeeze on a higher timeframe. A 15-minute squeeze confirmed by a 1-hour squeeze has much higher probability. See our MTF analysis guide for implementation details.
Trend context: Squeezes that resolve in the direction of the higher-timeframe trend succeed more often. Use the Supertrend indicator for trend direction confirmation.
FAQ: Bollinger Bands Squeeze Strategy
Q: What's the best timeframe for squeeze trading?
A: 4-hour and daily charts produce the most reliable squeezes. 15-minute charts have more noise. Start with 4H on large-cap stocks.
Q: Should I trade all squeezes or wait for confirmation?
A: Always wait for the breakout candle. The squeeze itself is just a warning—the actual entry is the breakout with volume.
Q: Can I adjust the Bollinger Band settings?
A: Yes, but 20 period with 2 std dev is standard. Tighter bands (1.5 std dev) give more entries but more false signals. Backtest any changes thoroughly.
Q: How long does a typical squeeze last?
A: Usually 3-20 candles depending on timeframe. When it lasts longer than 30 candles, be cautious—it might resolve sideways.
Q: Is this strategy suitable for proper risk management?
A: Absolutely. The middle band provides a natural stop-loss level, making position sizing straightforward. Risk 1-2% per trade with stop at the SMA 20.
Need a Custom Pine Script Solution?
Jayadev Rana is a professional Pine Script developer who builds custom indicators, strategies, and automated trading systems for TradingView.