Indicator · Pine Script v5 · On the chart

Stella's Bollinger Squeeze

by stella-entry

Stella's Bollinger Squeeze plots Bollinger Bands and compares them with a Keltner Channel on the price chart.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code56
Settings5inputs
LicenceMIT
Last update8 months ago22 Feb 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

56 lines of Pine Script v5 from indicators/bollinger-squeeze.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

bollinger-squeeze.pine
//@version=5
indicator("Stella's Bollinger Squeeze", shorttitle="BSQ", overlay=true)

// Bollinger Bands Squeeze Detector
// Identifies low volatility periods before potential breakouts

// Settings
length = input(20, "BB Length")
mult = input(2.0, "BB Multiplier")
kc_length = input(20, "KC Length")
kc_mult = input(1.5, "KC Multiplier")
squeeze_threshold = input(0.5, "Squeeze Threshold")

// Bollinger Bands
basis = ta.sma(close, length)
dev = mult * ta.stdev(close, length)
upper_bb = basis + dev
lower_bb = basis - dev

// Keltner Channel
kc_basis = ta.sma(close, kc_length)
range_val = ta.sma(ta.tr, kc_length)
upper_kc = kc_basis + kc_mult * range_val
lower_kc = kc_basis - kc_mult * range_val

// Squeeze detection
squeeze = (upper_bb < upper_kc) and (lower_bb > lower_kc)
no_squeeze = (upper_bb > upper_kc) and (lower_bb < lower_kc)

// Squeeze intensity
bb_width = (upper_bb - lower_bb) / basis
kc_width = (upper_kc - lower_kc) / kc_basis
squeeze_ratio = bb_width / kc_width

// Plot Bollinger Bands
plot(basis, "BB Basis", color=color.blue)
p1 = plot(upper_bb, "BB Upper", color=color.blue)
p2 = plot(lower_bb, "BB Lower", color=color.blue)
fill(p1, p2, color=color.new(color.blue, 90))

// Squeeze visual
bgcolor(squeeze ? color.new(color.yellow, 70) : na, title="Squeeze")
bgcolor(no_squeeze ? color.new(color.gray, 90) : na, title="No Squeeze")

// Breakout signals
breakout_up = ta.crossover(close, upper_bb) and not squeeze
breakout_down = ta.crossunder(close, lower_bb) and not squeeze

plotshape(breakout_up, "Breakout Up", shape.triangleup, location.belowbar, color.green, size=size.small)
plotshape(breakout_down, "Breakout Down", shape.triangledown, location.abovebar, color.red, size=size.small)

// Alerts
alertcondition(squeeze, "Squeeze Formed", "Bollinger Squeeze detected")
alertcondition(breakout_up, "Breakout Up", "Price broke above BB")
alertcondition(breakout_down, "Breakout Down", "Price broke below BB")
alertcondition(ta.crossover(squeeze_ratio, squeeze_threshold), "Squeeze Relaxing", "Volatility expanding")

Overview

Stella's Bollinger Squeeze marks a squeeze when the Bollinger Bands sit inside the Keltner Channel and a gray background when they sit outside. After the squeeze ends, it marks upward and downward closes that cross the outer bands. Lengths, multipliers, and a squeeze-ratio threshold change the bands and a volatility-expansion alert. It does not manage positions or exits.

Details

Published by

stella-entry on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Volatility & bands, Breakout

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 Lengthint20length
BB Multiplierfloat2.0mult
KC Lengthint20kc_length
KC Multiplierfloat1.5kc_mult
Squeeze Thresholdfloat0.5squeeze_threshold
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

Raschke Patterns

by TradersPost
218 stars

This overlay indicator marks Linda Raschke short-term bar setups on the price chart. It flags Turtle Soup and Turtle Soup plus one false breakouts of a prior extreme, 80-20 bars, inside bars, failed inside-bar breakouts, outside up and down bars, NR4 and NR7 c

Indicator v6 Candlestick patternsBreakout Repaints
Updated 3 months ago · None stated GitHub repository of Raschke Patterns

Acceleration Bands

by capissimo
114 stars

Acceleration Bands is an overlay indicator that plots a volatility envelope around a central simple moving average. It calculates upper and lower boundary bands scaled by the high-to-low bar range relative to the midpoint price, smoothed by an SMA over a user-

Indicator v4 Volatility & bandsMoving averages
Updated 1 year ago · None stated GitHub repository of Acceleration Bands

Donchian Channels (DC)

by mihakralj
99 stars

This indicator calculates and plots Donchian Channels directly on the price chart. It determines the highest high and lowest low over a user-selected lookback period using an optimized monotonic deque algorithm, as well as a middle basis line computed as their

Indicator v6 Volatility & bandsSupport & resistance
Updated 4 weeks ago · Apache-2.0 GitHub repository of Donchian Channels (DC)
47 stars

The Donchian Channels indicator plots the middle basis line as the average of the high and low over the user-defined period. It also draws the upper band as the highest high and the lower band as the lowest low across the same period on the price chart. The ma

Indicator v6 Volatility & bandsSupport & resistance
Updated 8 months ago · MIT GitHub repository of Donchian Channels (DCHANNEL)
43 stars

This indicator plots Donchian channel bands and a midline on the price chart. It finds the highest and lowest values over a user-set length, then draws the upper band, lower band, and their average as the basis. The source setting chooses high and low, or the

Indicator v4 Volatility & bandsBreakout
Updated 1 year ago · None stated GitHub repository of Donchian Channels Experiment

Donchian Channels

by TWODS-CAPITAL
37 stars

This indicator plots a Donchian channel on the price chart. It calculates the highest high and the lowest low over a user-set lookback, then draws those values as upper and lower bands with a midline equal to their average. The area between the bands is filled

Indicator v5 Volatility & bandsBreakout
Updated 3 years ago · MIT GitHub repository of Donchian Channels

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers