BreakoutIntermediateBollinger BandsATRVolume

Bollinger Band Squeeze Strategy

Bollinger Bands contract during low-volatility periods (the "squeeze") and expand during breakouts. This strategy identifies the squeeze by measuring band width relative to its recent range, then enters when price breaks out of the bands with volume confirmation.

Best for: Crypto and volatile assets — 4H and DailyTimeframes: 4H, Daily

Pine Script v6 — Complete Strategy Code

//@version=6
bollinger-band-squeeze-pine-script.pine
//@version=6
strategy("Bollinger Band Squeeze", overlay=true,
     default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// ── Inputs ──
int   bbLen   = input.int(defval=20,   title="BB Length",    minval=1,   group="Bollinger")
float bbMult  = input.float(defval=2.0, title="BB StdDev",  minval=0.1, step=0.1, group="Bollinger")
int   sqzLen  = input.int(defval=20,   title="Squeeze Lookback", minval=1, group="Squeeze")
int   volLen  = input.int(defval=20,   title="Volume MA Length", minval=1, group="Volume")
float slMult  = input.float(defval=1.5, title="SL ATR Mult", minval=0.1, step=0.1, group="Risk")
float tpMult  = input.float(defval=3.0, title="TP ATR Mult", minval=0.1, step=0.1, group="Risk")

// ── Calculations ──
[upper, mid, lower] = ta.bb(close, bbLen, bbMult)
float bbWidth   = upper - lower
float sqzThresh = ta.lowest(bbWidth, sqzLen) * 1.1
bool  inSqueeze = bbWidth <= sqzThresh
float volMa     = ta.sma(volume, volLen)
float atr       = ta.atr(14)

bool longCond  = close > upper and inSqueeze[1] and volume > volMa
bool shortCond = close < lower and inSqueeze[1] and volume > volMa

// ── Visuals ──
plot(upper, "BB Upper", color.new(color.blue, 60))
plot(mid,   "BB Mid",   color.new(color.blue, 80))
plot(lower, "BB Lower", color.new(color.blue, 60))
bgcolor(inSqueeze ? color.new(color.yellow, 92) : na, title="Squeeze Zone")
plotshape(longCond,  style=shape.triangleup,   location=location.belowbar, color=color.green, size=size.small)
plotshape(shortCond, style=shape.triangledown, location=location.abovebar, color=color.red,   size=size.small)

// ── Orders ──
if longCond
    strategy.entry("Long", strategy.long)
    strategy.exit("XL", from_entry="Long", stop=close - atr * slMult, limit=close + atr * tpMult)
if shortCond
    strategy.entry("Short", strategy.short)
    strategy.exit("XS", from_entry="Short", stop=close + atr * slMult, limit=close - atr * tpMult)

// ── Alerts ──
alertcondition(longCond,  title="BB Squeeze Long",  message="BB squeeze breakout long — {{ticker}}")
alertcondition(shortCond, title="BB Squeeze Short", message="BB squeeze breakout short — {{ticker}}")

Copy and paste into TradingView Pine Editor, or generate a custom variation with AI.

How it works

Strategy logic, step by step

  1. 1

    Bollinger Bands (20 period, 2.0 std dev) are calculated using ta.bb().

  2. 2

    Band width (upper - lower) is compared to its lowest value over 20 bars.

  3. 3

    Squeeze detected when band width is at or near its 20-bar low.

  4. 4

    Long entry: price breaks above the upper band during a squeeze.

  5. 5

    Short entry: price breaks below the lower band during a squeeze.

  6. 6

    Volume confirmation: current volume must be above the 20-bar average.

Parameters

Configurable inputs

ParameterDefault
BB Length20
BB StdDev2.0
Squeeze Lookback20
Volume MA Length20

Ask the TradePilot copilot to backtest this and sweep the inputs to find the best combination for your asset and timeframe.

FAQ

Bollinger Band Squeeze Strategy questions

What is the Bollinger Band squeeze?

The squeeze occurs when Bollinger Bands contract to their narrowest point — a sign that volatility has compressed and a breakout is likely. The direction of the breakout determines whether to go long or short.

Why add volume confirmation?

False breakouts (price briefly crossing a band then reversing) are common without volume. Requiring volume above its moving average ensures the breakout has conviction behind it.

More strategies

Other Pine Script strategies

Want a custom version of this strategy?

Describe your modifications in plain English — different indicators, different risk parameters, long-only, multi-timeframe filter — and TradePilot generates the full Pine Script v6 code in seconds.