Bollinger Squeeze Breakout — Pine Script v5 strategy
This script takes the opposite view of the lower-band bounce: it waits for the Bollinger Bands to tighten, then buys when the close crosses above the upper band. It exits as soon as price falls back below the middle line.
Full code (free to copy)
//@version=5
strategy("Bollinger Squeeze Breakout", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)
length = input.int(20, "BB Length", minval=10, maxval=50)
mult = input.float(2.0, "BB Mult", minval=1.2, maxval=3.2, step=0.2)
[basis, upper, lower] = ta.bb(close, length, mult)
bw = (upper - lower) / basis
compressed = bw[1] < ta.sma(bw, length)[1]
if compressed and ta.crossover(close, upper)
strategy.entry("Long", strategy.long)
if ta.crossunder(close, basis)
strategy.close("Long")
plot(upper, "Upper", color=color.aqua)
plot(basis, "Midline", color=color.orange)Judge this code on BTCUSDT 1D →Free, in your browser, on the same candles as the table below.
Online judge verdict on BTCUSDT (measured 29 November 2026)
| Timeframe | Sealed period | Trades | Return | Buy & hold | Verdict |
|---|---|---|---|---|---|
| 1d | 2024-12-17 → 2026-10-16 | 10 | -18.17 % | -23.25 % | No evidence of an edge, for now |
| 4h | 2026-03-12 → 2026-10-17 | 21 | 8.83 % | 15.83 % | No evidence of an edge yet: 1 of 4 steps passed |
| 1h | 2026-08-05 → 2026-10-17 | 29 | 20.04 % | 27.14 % | No evidence of an edge, for now |
Past data, 10 bps per fill, last 20% of the bars sealed. Windows: full history on 1d, last 3 years on 4h, last year on 1h. Research, not advice: no result is promised.
This reading has not been compared with a real TradingView run.
Measured on 29 November 2026 with the online judge’s Pine v5 engine (sa-pine-vm 0.2.0), on Binance BTCUSDT candles up to 16/10/2026 on 1D and up to 17/10/2026 on 4h and 1h. Differences with TradingView’s Strategy Tester remain possible. Binance data, CC BY-NC-SA 4.0.
Open this code in the free judge (1 click) →
Replay each verdict yourself, in your browser: 1d · 4h · 1h. The script is filled in; nothing runs until you click “Judge”.
How the script works
ta.bb(close, length, mult) returns the middle line (basis) and both bands, with length = 20 and mult = 2.0 by default. The relative width bw = (upper - lower) / basis measures volatility.
The compressed condition compares the previous bar's width with its 20-bar average, also shifted by one bar. Entry requires compressed and ta.crossover(close, upper); the exit happens on ta.crossunder(close, basis).
Parameters in the code
| Parameter | Value | Role |
|---|---|---|
length | 20 | Input "BB Length" created with input.int, from 10 to 50. |
mult | 2.0 | Input "BB Mult" created with input.float, from 1.2 to 3.2. |
initial_capital | 10000 | Starting capital declared in strategy(). |
default_qty_type | percent_of_equity, 100 | Each entry commits 100% of available equity. |
commission_value | 0.1 (%) | 0.10% commission per order declared in the script; the judge applies it (10 bps per fill). |
process_orders_on_close | not set | Orders fill at the open of the next bar, the Pine default. |
Known limits of this rule
- Many breakouts after a squeeze fail and fall back inside the bands: the exit below the middle line then costs a round trip of fees.
- The squeeze is defined against the average width, not an absolute level: in an already quiet market it is true very often.
- Long only: a downside breakout is not traded.
Before you trust it: test it on data it never saw
A backtest in TradingView's Strategy Tester shows one past path with the settings you picked. Strategy Arena Lab (free, Windows and Linux) replays this Pine on your PC, compares its trades one by one with TradingView's for supported Pine, counts the variants you try, then judges the rule on a period kept sealed during the search: survives, no evidence of an edge or inconclusive.
FAQ
What does the online judge say about this script?
On BTCUSDT, with 10 bps fees per fill, measured on 29 November 2026: 1D: "No evidence of an edge, for now" (10 trades, -18.17% on the sealed period); 4h: "No evidence of an edge yet: 1 of 4 steps passed" (21 trades, 8.83% on the sealed period); 1h: "No evidence of an edge, for now" (29 trades, 20.04% on the sealed period). No timeframe reaches "Survives". These verdicts concern past data and say nothing certain about the future.
How is it different from the lower-band bounce?
The bounce buys below the lower band, betting on a return to the mean. This script does the opposite: it buys above the upper band, betting that the move continues after a quiet period.
Can I change the script's settings?
Yes, the settings are inputs you can edit in TradingView. Each setting you try is one more trial: a setting chosen after seeing the sealed period is no longer a test on unseen data. The judge and the Lab count trials for this reason.
Other free Pine Script v5 strategies
More TradingView paths
Educational code on past data. No investment advice; no result is promised.