Indicator · Pine Script v6 · Own pane

TTM Squeeze Divergence

by TamaraKGreen· code credited to notprofessorgreen

The TTM Squeeze Divergence indicator plots a classic TTM Squeeze momentum oscillator in a separate pane alongside Bollinger Bands and Keltner Channels squeeze status dots on the zero line.

View on GitHub

Repaints

GitHub stars46on the repository
Pine versionv6current
Lines of code127
Settings15inputs
LicenceNone statedfile: MPL-2.0
Last update7 weeks ago4 Sep 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

127 lines of Pine Script v6 from TTM Squeeze Divergence.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

TTM Squeeze Divergence.txt
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © notprofessorgreen
//@version=6

indicator(title = 'TTM Squeeze divergence',shorttitle = 'Sqz', overlay = false)

length = input(20, title = 'BB Length')
mult = input(2.0, title = 'BB MultFactor')
lengthKC = input(20, title = 'KC Length')
multKC = input(1.5, title = 'KC MultFactor')

useTrueRange = input(true, title = 'Use TrueRange (KC)')

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

// Calculate KC
ma = ta.sma(source, lengthKC)
range_1 = useTrueRange ? ta.tr : high - low
rangema = ta.sma(range_1, 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)

iff_1 = val > nz(val[1]) ? color.yellow : color.orange
iff_2 = val < nz(val[1]) ? color.red : color.maroon
bcolor = val > 0 ? iff_1 : iff_2
scolor = noSqz ? color.blue : sqzOn ? color.black : color.gray
plot(val, color = bcolor, style = plot.style_histogram, linewidth = 4)
plot(0, color = scolor, style = plot.style_cross, linewidth = 2)

overlay_main = input(false, title = 'Plot on price (rather than on indicator)')
osc = val
lbR = input(title = 'Pivot Lookback Right', defval = 5)
lbL = input(title = 'Pivot Lookback Left', defval = 5)
rangeUpper = input(title = 'Max of Lookback Range', defval = 60)
rangeLower = input(title = 'Min of Lookback Range', defval = 5)
plotBull = input(title = 'Plot Bullish', defval = true)
plotHiddenBull = input(title = 'Plot Hidden Bullish', defval = false)
plotBear = input(title = 'Plot Bearish', defval = true)
plotHiddenBear = input(title = 'Plot Hidden Bearish', defval = false)
delay_plot_til_closed = input(title = 'Delay plot until candle is closed (don\'t repaint)', defval = false)
bearColor = color.red
bullColor = color.green
hiddenBullColor = color.new(color.green, 80)
hiddenBearColor = color.new(color.red, 80)
textColor = color.white
noneColor = color.new(color.white, 100)

repaint = not delay_plot_til_closed or barstate.ishistory or barstate.isconfirmed

plFound = na(ta.pivotlow(osc, lbL, lbR)) ? false : true
phFound = na(ta.pivothigh(osc, lbL, lbR)) ? false : true
_inRange(cond) =>
    bars = ta.barssince(cond == true)
    rangeLower <= bars and bars <= rangeUpper

//------------------------------------------------------------------------------
// Regular Bullish
// Osc: Higher Low

oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])

// Price: Lower Low

priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)
bullCond = plotBull and priceLL and oscHL and plFound and repaint

plot(plFound ? overlay_main ? low[lbR] : osc[lbR] : na, offset = -lbR, title = 'Regular Bullish', linewidth = 2, color = bullCond ? bullColor : noneColor)

plotshape(bullCond ? overlay_main ? low[lbR] : osc[lbR] : na, offset = -lbR, title = 'Regular Bullish Label', text = ' Bull ', style = shape.labelup, location = location.absolute, color = color.new(bullColor, 0), textcolor = color.new(textColor, 0))

//------------------------------------------------------------------------------
// Hidden Bullish
// Osc: Lower Low

oscLL = osc[lbR] < ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1])

// Price: Higher Low

priceHL = low[lbR] > ta.valuewhen(plFound, low[lbR], 1)
hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound and repaint

plot(plFound ? overlay_main ? low[lbR] : osc[lbR] : na, offset = -lbR, title = 'Hidden Bullish', linewidth = 2, color = hiddenBullCond ? hiddenBullColor : noneColor)

plotshape(hiddenBullCond ? overlay_main ? low[lbR] : osc[lbR] : na, offset = -lbR, title = 'Hidden Bullish Label', text = ' H Bull ', style = shape.labelup, location = location.absolute, color = color.new(bullColor, 0), textcolor = color.new(textColor, 0))

//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High

oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])

// Price: Higher High

priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)

bearCond = plotBear and priceHH and oscLH and phFound and repaint

plot(phFound ? overlay_main ? high[lbR] : osc[lbR] : na, offset = -lbR, title = 'Regular Bearish', linewidth = 2, color = bearCond ? bearColor : noneColor)

plotshape(bearCond ? overlay_main ? high[lbR] : osc[lbR] : na, offset = -lbR, title = 'Regular Bearish Label', text = ' Bear ', style = shape.labeldown, location = location.absolute, color = color.new(bearColor, 0), textcolor = color.new(textColor, 0))

//------------------------------------------------------------------------------
// Hidden Bearish
// Osc: Higher High

oscHH = osc[lbR] > ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1])

// Price: Lower High

priceLH = high[lbR] < ta.valuewhen(phFound, high[lbR], 1)

hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound and repaint

plot(phFound ? overlay_main ? high[lbR] : osc[lbR] : na, offset = -lbR, title = 'Hidden Bearish', linewidth = 2, color = hiddenBearCond ? hiddenBearColor : noneColor)

plotshape(hiddenBearCond ? overlay_main ? high[lbR] : osc[lbR] : na, offset = -lbR, title = 'Hidden Bearish Label', text = ' H Bear ', style = shape.labeldown, location = location.absolute, color = color.new(bearColor, 0), textcolor = color.new(textColor, 0))

Overview

TTM Squeeze Divergence detects regular and hidden bullish and bearish divergences between price swings and oscillator pivot highs or lows. Users can adjust Bollinger Band and Keltner Channel parameters, pivot lookback lengths, and divergence evaluation ranges. Plots can be offset historically or delayed until candle close to mitigate live-bar repainting, though unconfirmed pivots naturally repaint until right bars confirm.

Details

Published by

TamaraKGreen on GitHub

Code credit

notprofessorgreen, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Volatility & bands, Divergence

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

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

SettingTypeDefaultVariable
BB Lengthint20length
BB MultFactorfloat2.0mult
KC Lengthint20lengthKC
KC MultFactorfloat1.5multKC
Use TrueRange (KC)booltrueuseTrueRange
Plot on price (rather than on indicator)boolfalseoverlay_main
Pivot Lookback Rightint5lbR
Pivot Lookback Leftint5lbL
Max of Lookback Rangeint60rangeUpper
Min of Lookback Rangeint5rangeLower
Plot BullishbooltrueplotBull
Plot Hidden BullishboolfalseplotHiddenBull
Show all 15 settings
SettingTypeDefaultVariable
Plot BearishbooltrueplotBear
Plot Hidden BearishboolfalseplotHiddenBear
Delay plot until candle is closed (don't repaint)boolfalsedelay_plot_til_closed
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

330 stars

This indicator plots a TTM Squeeze momentum oscillator and a MACD line in a separate pane. It builds the squeeze oscillator from a linear regression of price against a high-low and simple moving average midpoint, and colors the area by slope and sign. Circles

Indicator v5 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of TTM Squeeze + MACD line [Alorse]

Bubbles Indicator

by capissimo
114 stars

The Bubbles Indicator measures volatility squeezes and expansion bursts using Bollinger Bands combined with a sinusoid oscillator and RSI divergence. It processes price data through scaled Bollinger Bands to highlight volatility changes while confirming trend

Indicator v4 Volatility & bandsOscillators & momentum Repaints
Updated 1 year ago · None stated GitHub repository of Bubbles Indicator

QFA Pro Elite Refined

by JasonTeixeira
9 stars

This indicator plots a smoothed fear index in a separate pane. It measures how far the current low sits below the highest close over a lookback, scales that reading by an ATR percentile, and smooths it with a zero-lag EMA. A volatility regime raises or lowers

Indicator v6 Oscillators & momentumVolatility & bands
Updated 12 days ago · Custom licence GitHub repository of QFA Pro Elite Refined

RSI Div at dVWAP StDev

by cryptorife
75 stars

This indicator marks RSI divergences only when price trades beyond daily VWAP standard-deviation bands. It compares recent RSI extremes with price highs and lows over a lookback window, and it treats a divergence as valid only while RSI stays beyond overbought

Indicator v4 DivergenceOscillators & momentum Repaints
Updated 3 years ago · GPL-3.0 GitHub repository of RSI Div at dVWAP StDev
8 stars

This indicator detects contrarian inflection points and potential market reversals by combining sentiment, volume, and price action metrics directly on the price chart. It evaluates overbought and oversold conditions with the RSI and Stochastic oscillators, hi

Indicator v5 Oscillators & momentumVolatility & bands
Updated 7 weeks ago · None stated GitHub repository of GCR Inflection Point Scanner

This indicator projects a dual-asset momentum matrix visualizer directly onto the price chart overlay. It calculates normalized momentum for the chart symbol using either RSI or Stochastic inputs adjusted by ATR volatility, and compares it against a benchmark

Indicator v6 Oscillators & momentumVolatility & bands Repaints
Updated 3 months ago · None stated GitHub repository of Pro Grid Elite: Advanced Dual-Asset Momentum Matrix

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