Indicator · Pine Script v5 · On the chart

Squeeze Momentum

by g-moe· code credited to goodgains

This overlay indicator combines classic Bollinger Band and Keltner Channel squeeze detection with linear regression momentum and pivot-based support and resistance levels.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code130
Settings14inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 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

130 lines of Pine Script v5 from Tradingview/squeeze-momentum.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

squeeze-momentum.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
indicator("Squeeze Momentum", overlay = true, max_lines_count = 500)

// @keywords: ttm-squeeze, bollinger-keltner, squeeze-release, linear-regression, momentum-direction, support-resistance, pivot-lines, buy-sell-labels, squeeze-count, release-count, ma-filter, sr-crossover, momentum-bars, squeeze-on, squeeze-off, case-signals, trend-momentum, resistance-break, support-break, alert-signals

// ma settings
ma_length       = input.int(200, title = 'MA Length   ', group = 'MA Settings', inline = '2')
ma_source       = input.source(close, title = 'MA Source   ', group = 'MA Settings', inline = '3')


// squeeze settings
length              = input.int(20, title="BB Length    ", group = 'Squeeze Settings', inline = '2')
mult                = input.float(2.0,title="BB MultFactor  ", group = 'Squeeze Settings', inline = '3')
lengthKC            = input.int(20, title="KC Length    ", group = 'Squeeze Settings', inline = '4')
multKC              = input.float(1.5, title="KC MultFactor  ", group = 'Squeeze Settings', inline = '5')
useTrueRange        = input.bool(true, title="Use TrueRange (KC)", group = 'Squeeze Settings', inline = '6')


// s/r lines
left_bars = input.int(15, title = "S/R Left Bars", group = 'S/R Settings', inline = '1')
right_bars = input.int(15, title = "S/R Right Bars", group = 'S/R Settings', inline = '1')
resistance_color = input.color(color.new(#2a9037, 0), title = 'Resistance', group = 'S/R Settings', inline = '2')
support_color = input.color(color.new(#FF0000, 0), title = 'Support', group = 'S/R Settings', inline = '2')











// ma
ma_value = ta.sma(ma_source, ma_length)
plot(ma_value, title = 'MA', color=color.new(#F3ACF1,0))

ma_buy = close > ma_value
ma_sell = close < ma_value


// squeeze momentum
var int bg_color = 0
var int sqz_count = 0
var int release_count = 0
var int sqz_type = 0

// Calculate BB
source = close
basis = ta.sma(source, length)
dev = multKC * ta.stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev

// Calculate KC
ma = ta.sma(source, lengthKC)
range_src = useTrueRange ? ta.tr : (high - low)
rangema = ta.sma(range_src, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC

sqzOn  = (lowerBB > lowerKC) and (upperBB < upperKC)
sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
noSqz  = (sqzOn == false) and (sqzOff == false)

val = ta.linreg(source  -  math.avg(math.avg(ta.highest(high, lengthKC), ta.lowest(low, lengthKC)), ta.sma(close,lengthKC)), lengthKC,0)

// lime=1 green=2 red=-1 maroon=-2
bg_color := val > 0 and val > val[1] ? 1 : val > 0 and val < val[1] ? 2 : val < 0 and val < val[1] ? -1 : -2

sqz_type := sqzOn ? 1 : sqzOff ? -1 : sqz_type[1]
sqz_count := sqzOn and not sqzOn[1] ? 1 : sqzOn ? sqz_count[1] + 1 : sqz_count[1]
release_count := not sqzOn and sqzOn[1] ? 1 : not sqzOn ? release_count[1] + 1 : release_count[1]


// s/r
resistance_value = ta.valuewhen(ta.pivothigh(high,left_bars,right_bars), high[right_bars], 0)
support_value = ta.valuewhen(ta.pivotlow(low,left_bars,right_bars), low[right_bars], 0)
var line resistance = na
var line support = na
var int bars_since_rcross = na
var int bars_since_scross = na

if resistance_value != resistance_value[1]
    line.set_extend(resistance, extend.none)
    resistance := line.new(x1 = time[right_bars], y1 = resistance_value, x2 = time[right_bars + 1], y2 = resistance_value,
     color = resistance_color, extend = extend.right, xloc = xloc.bar_time)
else
    line.set_x2(resistance, time)
if support_value != support_value[1]
    line.set_extend(support, extend.none)
    support := line.new(x1 = time[right_bars], y1 = support_value, x2 = time[right_bars + 1], y2 = support_value,
     color = support_color, extend = extend.right, xloc = xloc.bar_time)
else
    line.set_x2(support, time)

sr_buy = (close >= line.get_y1(resistance))
sr_sell = (close <= line.get_y1(support))

bars_since_rcross := ta.crossover(close,resistance_value) ? 1 : bars_since_rcross[1] + 1
bars_since_scross := ta.crossunder(close,support_value) ? 1 : bars_since_scross[1] + 1


// create signals
case1a = input.bool(true, title = 'Case 1A', group = 'Trading Settings', inline = '1')
case1b = input.bool(true, title = 'Case 1B', group = 'Trading Settings', inline = '2')
squeeze_bars_required = input.int(6, title = 'Squeeze Bars Required', group = 'Trading Settings', inline = '4')

case1_buya = case1a and (close > ma_value) and (bars_since_rcross==1) and (bg_color == 1 and sqz_type == -1 and release_count == 1 and sqz_count >= squeeze_bars_required) 
case1_buyb = case1b and (close > ma_value) and (bars_since_rcross<=4) and (bg_color == 1 and sqz_type == -1 and release_count == 1 and sqz_count >= squeeze_bars_required) 

case1_sella = case1a and (close < ma_value) and (bars_since_scross==1) and (bg_color == -1 and sqz_type == -1 and release_count == 1 and sqz_count >= squeeze_bars_required) 
case1_sellb = case1b and (close < ma_value) and (bars_since_scross<=4) and (bg_color == -1 and sqz_type == -1 and release_count == 1 and sqz_count >= squeeze_bars_required) 
// barcolor(sqztype == 1 ? color.orange : sqztype == -1 ? color.white : na)
// bgcolor(case1_buya ? color.new(color.green,70) : case1_sella ? color.new(color.red,70) : na)


// signal labels
plotshape(case1_buya or case1_buyb, style=shape.labelup, editable=false, text= "BUY", textcolor=color.white, location= location.belowbar, color=color.green, size=size.tiny)
plotshape(case1_sella or case1_sellb, style=shape.labeldown, editable=false, text='SELL', textcolor=color.white, location=location.abovebar, color=color.red, size=size.tiny)


// alerts
alertcondition(case1_buya or case1_buyb, "Buy Signal", "Buy Signal")
alertcondition(case1_sella or case1_sellb, "Sell Signal", "Sell Signal")

Overview

Squeeze Momentum plots a long-term moving average filter and tracks squeeze compression and release counts. When volatility squeezes and momentum aligns, it evaluates breakout conditions against dynamic pivot support and resistance lines directly on the price chart. Users can configure moving average parameters, squeeze band multipliers, pivot lookback periods, and minimum squeeze duration requirements.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Draws

On the price chart

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
MA Length   int200ma_length
MA Source   sourceclosema_source
BB Length    int20length
BB MultFactor  float2.0mult
KC Length    int20lengthKC
KC MultFactor  float1.5multKC
Use TrueRange (KC)booltrueuseTrueRange
S/R Left Barsint15left_bars
S/R Right Barsint15right_bars
Resistancecolorcolor.new(#2a9037, 0)resistance_color
Supportcolorcolor.new(#FF0000, 0)support_color
Case 1Abooltruecase1a
Show all 14 settings
SettingTypeDefaultVariable
Case 1Bbooltruecase1b
Squeeze Bars Requiredint6squeeze_bars_required
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

Super Algo Setup [Aura]

by IAMATOMIC001
3 stars

This overlay indicator combines SuperTrend, RSI, MACD, and an EMA to mark labeled tops and bottoms on the price chart. Optional filters hide repeating signals and keep only relevant exits, and a Krypton fear-and-greed filter can limit bottoms and tops to overs

Indicator v5 Oscillators & momentumMoving averages
Updated 12 months ago · None stated GitHub repository of Super Algo Setup [Aura]
1 stars

This indicator plots envelope bands based on a moving average or exponential moving average of a chosen price source. It computes RSI with user-set length and source. Signals trigger on crossovers: buy when price crosses the lower envelope band while RSI falls

Indicator v5 Oscillators & momentumMoving averages
Updated 1 year ago · None stated GitHub repository of ENVELOPE - RSI - Buy Sell Signals
1 stars

US Momentum Swing Screener is a daily chart overlay indicator for US equities and ETFs. It plots a composite score based on an EMA ribbon (9/21/50/200), RSI and StochRSI momentum, MACD confluence, volume surge detection, ADX trend strength, Bollinger Band posi

Indicator v5 Oscillators & momentumMoving averages
Updated 4 months ago · None stated GitHub repository of US Momentum Swing Screener

Composite Market Bias

by mrme000m
1 stars

Composite Market Bias is a separate-pane indicator that scores bullish and bearish conditions from RSI, fast versus slow EMA, MACD histogram, Bollinger Band position, and price versus a 50-period EMA. It plots the resulting bias score with RSI, EMA trend, MACD

Indicator v5 Oscillators & momentumMoving averages
Updated 7 weeks ago · None stated GitHub repository of Composite Market Bias

This overlay indicator plots a Supertrend from an ATR length and factor, four exponential moving averages, and a selectable VWAP or TWAP taken from a chosen timeframe on the price chart. It also shows MACD and stochastic with adjustable lengths, smoothing, ver

Indicator v5 Oscillators & momentumMoving averages
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup: Vijay Thakare Option Buying Scalping Setup

This indicator plots trade entry and exit signals on the price chart by combining Bollinger Bands with optional filter conditions. It calculates standard Bollinger Bands along with RSI, Aroon, and moving average filters. Reversal signals trigger when price bre

Indicator v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner IND [Alorse]

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