Indicator · Pine Script v5 · Own pane

Linear Regression

by g-moe· code credited to goodgains

This indicator calculates a TTM-style squeeze by comparing Bollinger Bands with Keltner Channels alongside a linear regression momentum oscillator.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code51
Settings6inputs
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

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

linear-regression-v3.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("Linear Regression", overlay=false)

// @keywords: linear-regression-v3, tt-squeeze-release, bollinger-keltner-squeeze, linear-regression-momentum, release-count-plot, squeeze-on-off-state, bb-kc-comparison, momentum-direction, squeeze-duration-count, orange-release-counter, panel-indicator, linreg-deviation, keltner-channel-squeeze, true-range-kc, multi-state-background, squeeze-timeframe, regression-val-plot, bb-length-mult, kc-length-mult, momentum-regression

// squeeze settings
squeeze_timeframe   = input.timeframe("", title = 'Squeeze Timeframe', group = 'Squeeze Settings', inline = '1')
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')

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 := sqz_type == 1 and sqz_type[1] != 1 ? 1 : sqzOn ? sqz_count[1] + 1 : sqz_count[1]
release_count := sqz_type == -1 and sqz_type[1] != -1 ? 1 : sqzOff ? release_count[1] + 1 : release_count[1]


plot(release_count, color = color.orange)

Overview

Linear Regression measures volatility compression when Bollinger Bands contract within the Keltner Channels and tracks the duration of squeeze state and release periods. Displayed in a separate pane, the indicator plots the release count value in orange. Users can adjust the length, multiplier factors, True Range option, and multi-timeframe evaluation setting for both channel indicators.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Volatility & bands

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
Squeeze Timeframetimeframesqueeze_timeframe
BB Length    int20length
BB MultFactor  float2.0mult
KC Length    int20lengthKC
KC MultFactor  float1.5multKC
Use TrueRange (KC)booltrueuseTrueRange
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

TTM Squeeze

by Alorse
330 stars

This indicator plots a TTM Squeeze momentum oscillator in a separate pane. It compares a Bollinger Band offset to a Keltner Channel offset and marks the zero line white when the difference is non-negative and black when the bands are inside the channel. A line

Indicator v5 Oscillators & momentumVolatility & bands
Updated 2 months ago · None stated GitHub repository of TTM Squeeze

Function - Logistic Equation

by ricardosantos79
261 stars

Calculates dynamic modeling values by applying a mathematical logistic differential equation to price change over a specified lookback length. It measures price momentum relative to the recent high-low price range. The script plots positive and negative logist

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 years ago · None stated GitHub repository of Function - Logistic Equation

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V
218 stars

This indicator detects a Bollinger Band squeeze when the bands sit inside Keltner Channels, marking low volatility. It plots red dots during a squeeze and green dots when the bands are outside, in a separate pane. An optional histogram shows momentum as the cl

Indicator v6 Volatility & bandsOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Bollinger Band Squeeze Detector
147 stars

This indicator generates trade entry signals and target levels optimized for 1-hour timeframes, designed for external signal extraction. It calculates 7-period and 16-period EMAs alongside 10-period RSI and ATR filters. Long signals occur when the fast EMA cro

Indicator v5 TrendOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of Signal Strategy 100 Candles of 1H Timeframe

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

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