Strategy · Pine Script v6 · On the chart

BB Squeeze Breakout

by pineforge-4pass· code credited to PineForge contributors 2026

A strategy that detects a volatility squeeze when Bollinger Bands sit inside Keltner Channels.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code57
Settings5inputs
LicenceApache-2.0
Last update6 days ago23 Oct 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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

57 lines of Pine Script v6 from validation/ta-bb-kc-squeeze-breakout-01/strategy.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

strategy.pine
// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// PF probe 02 — BB / KC squeeze breakout
// Purpose: parity test for ta.bb() + ta.kc() tuple returns and the BB-inside-KC
// squeeze-state derivation.
//
//@version=6
strategy("BB Squeeze Breakout", overlay=true, initial_capital=1000000, process_orders_on_close=false, pyramiding=1, commission_type=strategy.commission.percent, commission_value=0, slippage=0, default_qty_type=strategy.fixed, default_qty_value=1)

// === Inputs ===
bbLen  = input.int(20, "BB Length", minval=5)
bbMult = input.float(2.0, "BB Multiplier", step=0.1)
kcLen  = input.int(20, "KC Length", minval=5)
kcMult = input.float(1.5, "KC Multiplier", step=0.1)
src    = input.source(close, "Source")

// === Bollinger Bands (tuple) ===
[bbMid, bbUpper, bbLower] = ta.bb(src, bbLen, bbMult)

// === Keltner Channels (tuple) — now using ta.kc() directly ===
[kcMid, kcUpper, kcLower] = ta.kc(src, kcLen, kcMult)

// === Squeeze detection: BB inside KC ===
sqzOn  = bbLower > kcLower and bbUpper < kcUpper
sqzOff = bbLower < kcLower or bbUpper > kcUpper

// === Momentum ===
mom = ta.linreg(src - bbMid, bbLen, 0)

// === Track squeeze state ===
var bool wasSqueezed = false
if sqzOn
    wasSqueezed := true

// === Squeeze fires when BB expands outside KC ===
sqzFired = wasSqueezed and sqzOff

// === Entry signals ===
if sqzFired and mom > 0
    strategy.entry("Long", strategy.long)
    wasSqueezed := false
if sqzFired and mom < 0
    strategy.entry("Short", strategy.short)
    wasSqueezed := false

// === Exit on opposite momentum ===
if strategy.position_size > 0 and mom < 0
    strategy.close("Long")
if strategy.position_size < 0 and mom > 0
    strategy.close("Short")

plot(bbUpper, "BB Upper", color=color.blue)
plot(bbLower, "BB Lower", color=color.blue)
plot(kcUpper, "KC Upper", color=color.orange)
plot(kcLower, "KC Lower", color=color.orange)

Overview

After a squeeze, it waits for the bands to expand outside the channels, then enters long if a linear regression momentum value is positive or short if it is negative. Open trades close when momentum flips to the opposite sign. Band lengths, multipliers and the price source are adjustable. There is no stop loss. Bands are drawn on the price chart.

Details

Published by

pineforge-4pass on GitHub

Code credit

PineForge contributors 2026, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingbacktestingparitypine-scriptpinescriptquantitative-financetest-corpustradingview

Settings

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

SettingTypeDefaultVariable
BB Lengthint20bbLen
BB Multiplierfloat2.0bbMult
KC Lengthint20kcLen
KC Multiplierfloat1.5kcMult
Sourcesourceclosesrc
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

257 stars

This strategy plots VWMA-based Bollinger bands on the 1-minute ES futures price chart for volatility analysis and potential breakout identification. It calculates dynamic long and short stop loss and take profit levels using percentage inputs relative to entry

Strategy v6 Volatility & bandsSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of V1.6 ES - Futures 1M No Repaint
228 stars

This strategy detects price breakouts above rolling highest highs or below lowest lows over a customizable lookback period. It includes optional volume spike and ATR volatility threshold filters, along with bar confirmation rules. Positions are taken upon conf

Strategy v6 BreakoutVolatility & bands
Updated 3 months ago · None stated GitHub repository of Breakout Strategy Template

Bollinger Breakout

by hackingthemarkets
189 stars

This price-chart strategy plots a simple moving average and upper and lower bands built from the standard deviation of close, scaled by separate offset inputs. It enters a fixed quantity long when close crosses above the upper band and a fixed quantity short w

Strategy v4 Volatility & bandsBreakout
Updated 3 years ago · None stated GitHub repository of Bollinger Breakout

2 Candles Inside ATR

by hasnocool
106 stars

2 Candles Inside ATR is an overlay script that measures volatility compression across two consecutive candles. It calculates a smoothed Average True Range (ATR) and compares it against the combined high and low range of the current and previous bars. When the

Strategy v4 Volatility & bandsBreakout
Updated 2 years ago · GPL-3.0 GitHub repository of 2 Candles Inside ATR

均线突破交易系统

by tangly1024
76 stars

This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the

Strategy v5 TrendMoving averages
Updated 5 months ago · None stated GitHub repository of 均线突破交易系统

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