Indicator · Pine Script v4 · Own pane

Squeeze Panel

by amico1234· code credited to kruskakli

Squeeze Panel plots a volatility squeeze in a separate pane.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code123
Settings10inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago2 Mar 2024

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

123 lines of Pine Script v4 from Squeeze Panel.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Squeeze Panel.pine
//@version=4
//
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kruskakli
// -----------
// The Squeeze Panel makes use of a Bollinger Band and a Keltner Channel to identify
// a range that are compressed, or "squeezed". This is defined as when the BB is enclosed
// within the KC. 
//
// The idea is that a major break out could be expected at the end of the Squeeze.
//
// But the "squeeze" doesn't say anything about which direction the breakout will take.
// One suggestion is that the breakout will follow the current trend, so to aid with
// this a Linear Regression calculation try to show where the trend might be going.
// 
// But since we already have Wave A/B/C that indicates the short/medium/long trend
// a better alternative for the immediate breakout direction could be the Money Flow Index.
// MFI is commonly used to monitor the flow of money and/or momentum; a value above 50
// may indicate a Buy pressure and vice versa.
//
// CREDITS
// -------
// Keltner code taken from: LazyBear
// Wave A/B/C code taken from: UCSGEARS
// The panel idea taken from: lejmer
// Using MFI to spot the breakout: "The Secret Mindset" (Youtube Channel)
//
study("Squeeze Panel", overlay=false)

length = input(defval=20,    title="BB Length",     type=input.integer)
mult = input(defval=2.0,     title="BB MultFactor", type=input.float)
lengthKC = input(defval=20,  title="KC Length",     type=input.integer)
multKC = input(defval=1.5,   title="KC MultFactor", type=input.float)

brk_ind = input(defval="MFI", title="Breakout direction indicator", options=["MFI","LinReg"], type=input.string)
sq_lreg_len = input(defval=51, title="LinReg Length", type=input.integer)
mfi_len = input(defval=7, title="Money Flow Index Length", type=input.integer)

waveALength = input(title="Wave A Length", type=input.integer, defval=34, minval=0)
waveBLength = input(title="Wave B Length", type=input.integer, defval=89, minval=0)
waveCLength = input(title="Wave C Length", type=input.integer, defval=144, minval=0)

// Calculate BB
source = close
[basis, upperBB, lowerBB] = bb(close, length, mult)

// Calculate KC
// https://www.investopedia.com/terms/k/keltnerchannel.asp
ma = ema(hlc3, lengthKC)
range = atr(lengthKC)
rangema = ema(range, 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 = linreg(source  -  avg(avg(highest(high, sq_lreg_len), lowest(low, sq_lreg_len)),sma(close,sq_lreg_len)), sq_lreg_len,0)

MFI = mfi(hlc3, mfi_len)

// Use Green/Red that works for a color blind!
green1 = color.new(#00ff00, 0)
green2 = color.new(#00ee00, 0)
green3 = color.new(#00cd00, 0)

orangered1 = color.new(#ff4500, 0)
orangered2 = color.new(#ee4000, 0)
orangered3 = color.new(#cd3700, 0)

bcolor = iff( val > 0,
         iff( val > nz(val[1]), green2, green3),
         iff( val < nz(val[1]), orangered3, orangered2))
scolor = sqzOn ? color.white : color.gray

mfi_clr = MFI > 50 ? green2 : orangered2


// Wave A
afastMA1 = ema(close, 8)
aslowMA1 = ema(close, waveALength)
amacd1 =  afastMA1 - aslowMA1
asignal1 = ema(amacd1, waveALength)
ahist1 =  amacd1 - asignal1
wa = ahist1

// Wave B
bfastMA1 = ema(close, 8)
bslowMA1 = ema(close, waveBLength)
bmacd1 =  bfastMA1 - bslowMA1
bsignal1 = ema(bmacd1, waveBLength)
bhist1 =  bmacd1 - bsignal1
wb = bhist1

// Wave C
cfastMA1 = ema(close, 8)
cslowMA1 = ema(close, waveCLength)

cmacd1 =  cfastMA1 - cslowMA1
csignal1 = ema(cmacd1, waveCLength)
chist1 =  cmacd1 - csignal1
wc = chist1

// Plotting

bw_squeeze_bar_clr = scolor
bw_wz_bar_clr = brk_ind == "MFI" ? mfi_clr : bcolor
bw_wa_bar_clr = wa > 0 ? green2 : wa < 0 ? orangered2 : color.black
bw_wb_bar_clr = wb > 0 ? green2 : wb < 0 ? orangered2 : color.black
bw_wc_bar_clr = wc > 0 ? green2 : wc < 0 ? orangered2 : color.black

bw_squeeze_bar = 5
bw_wz_bar = 4
bw_wa_bar = 3
bw_wb_bar = 2
bw_wc_bar = 1

plot(bw_squeeze_bar, title="Squeeze", color = bw_squeeze_bar_clr, transp = 0, style = plot.style_columns)
plot(bw_wz_bar, title="Breakout Direction", color = bw_wz_bar_clr, transp = 0, style = plot.style_columns)
plot(bw_wa_bar, title="Wave A", color = bw_wa_bar_clr, transp = 0, style = plot.style_columns)
plot(bw_wb_bar, title="Wave B", color = bw_wb_bar_clr, transp = 0, style = plot.style_columns)
plot(bw_wc_bar, title="Wave C", color = bw_wc_bar_clr, transp = 0, style = plot.style_columns)

Overview

Squeeze Panel marks a squeeze when Bollinger Bands sit inside a Keltner Channel and marks when the bands expand outside it. The user chooses Money Flow Index or linear regression to color likely breakout direction. Three MACD-style Wave A, B, and C histograms show short, medium, and long trends. Length and multiplier inputs change the bands, channels, regression, money flow, and waves. It does not place trades or define exits.

Details

Published by

amico1234 on GitHub

Code credit

kruskakli, as written in the script's header

Type

Indicator, Pine Script v4

Draws

Separate pane below the 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
BB Lengthint20length
BB MultFactorfloat2.0mult
KC Lengthint20lengthKC
KC MultFactorfloat1.5multKC
Breakout direction indicatorstringMFIbrk_ind
LinReg Lengthint51sq_lreg_len
Money Flow Index Lengthint7mfi_len
Wave A Lengthint34waveALength
Wave B Lengthint89waveBLength
Wave C Lengthint144waveCLength
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

Chop and Explode

by capissimo
114 stars

This indicator measures market consolidation and breakout phases by computing a scaled Relative Strength Index (RSI) on normalized price data. It identifies chop zones when the RSI oscillates between 40 and 60, highlighting tight consolidation between 45 and 5

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of Chop and Explode

Squeeze Momentum

by mihakralj
99 stars

This indicator plots Squeeze Momentum in a separate pane. It compares Bollinger Bands with a Keltner Channel to mark a squeeze when the bands sit inside the channel. Momentum is a linear regression of price relative to a Donchian midline and an SMA, shown as a

Indicator v6 Volatility & bandsOscillators & momentum
Updated 4 weeks ago · Apache-2.0 GitHub repository of Squeeze Momentum

Renko Acceleration

by f-cksociety
11 stars

Calculates the time elapsed between consecutive bars to measure market speed and volatility, designed primarily for Renko chart blocks where bar duration varies. In Momentum mode, it contrasts the current duration against a 100-period moving average baseline,

Indicator v4 Volatility & bandsOscillators & momentum
Updated 4 years ago · MPL-2.0 GitHub repository of Renko Acceleration

MACD Breakout

by jerryinyang
5 stars

This indicator plots a higher-timeframe MACD breakout setup on the price chart and combines it with linear regression channels. It marks support and resistance zones from MACD histogram sensitivity, then filters them with the MACD zero line, a linear regressio

Indicator v4 Oscillators & momentumBreakout
Updated 2 years ago · None stated GitHub repository of MACD Breakout

Raschke Patterns

by TradersPost
228 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

GainzAlgo V2 Alpha

by Bakomebandias
8 stars

This overlay indicator scores breakouts of recent highs and lows against failed-breakout checks, EMA trend alignment, RSI momentum, and an ATR volatility band. It plots green buy and red sell labels when conditions pass a minimum score, and it prints ATR-based

Indicator v6 TrendOscillators & momentum
Updated 6 months ago · None stated GitHub repository of GainzAlgo V2 Alpha

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