Indicator · Pine Script v5 · On the chart

TVT BB Squeeze w/ 8 21 SMA/EMA

by namuan

TVT BB Squeeze w/ 8 21 SMA/EMA is an overlay indicator that identifies consolidation squeezes and multi-timeframe trends.

View on GitHub

GitHub stars321on the repository
Pine versionv5runs as is
Lines of code49
Settings7inputs
LicenceMIT
Last update8 days ago16 Nov 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

49 lines of Pine Script v5 from tv-scripts/tvt_bb_squeeze_8_21_ema.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

tvt_bb_squeeze_8_21_ema.pine
//@version=5

indicator(title="[TVT] BB Squeeze w/ 8 21 SMA/EMA", shorttitle="TVT-BBS-821", overlay=true)

length = input.int(21, minval=1, title="Length")
src = input(close, title="Source")
use_ema = input.bool(true, title="Use EMA over SMA?")
k_mult = input.float(2, title="Keltner Range")
bb2_mult = input.float(2.0, minval=0.001, maxval=50, title="Band 1 StDev")
bb3_mult = input.float(3.0, minval=0.001, maxval=50, title="Band 2 StDev")
higher_res = input.timeframe(title="High Res 8x21 EMA TF", defval="D")

blend_color = color.white

ma = use_ema ? ta.ema(src, length) : ta.sma(src, length)

//BB 1
bb2_stdev = bb2_mult * ta.stdev(src, length)
bb2_upper = ma + bb2_stdev
bb2_lower = ma - bb2_stdev

//BB 2
bb3_stdev = bb3_mult * ta.stdev(src, length)
bb3_upper = ma + bb3_stdev
bb3_lower = ma - bb3_stdev

p_bb2_upper = plot(bb2_upper, color=blend_color, style=plot.style_line, linewidth=0, title="Band 2SD upper")
p_bb2_lower = plot(bb2_lower, color=blend_color, style=plot.style_line, linewidth=0, title="Band 2SD lower")
p_bb3_upper = plot(bb3_upper, color=blend_color, style=plot.style_line, linewidth=0, title="Band 3SD upper")
p_bb3_lower = plot(bb3_lower, color=blend_color, style=plot.style_line, linewidth=0, title="Band 3SD lower")

fill(p_bb2_upper, p_bb3_upper, color=color.red)
fill(p_bb2_lower, p_bb3_lower, color=color.green)

// Keltner Channel
k_range_ma = use_ema ? ta.ema(ta.tr, length) : ta.sma(ta.tr, length)
k_upper = ma + k_range_ma * k_mult
k_lower = ma - k_range_ma * k_mult

// Higher Res EMA
ema_8_high_res = request.security(syminfo.tickerid, higher_res, ta.ema(src, 8), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_off)
ema_21_high_res = request.security(syminfo.tickerid, higher_res, ta.ema(src, 21), gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_off)

ema_8_plt = plot(ema_8_high_res, color=ema_8_high_res > ema_21_high_res ? color.lime : color.maroon, style=plot.style_line, linewidth=0, title="EMA 8 (HTF)")
ema_21_plt = plot(ema_21_high_res, color=ema_8_high_res > ema_21_high_res ? color.lime : color.maroon, style=plot.style_line, linewidth=2, title="EMA 21 (HTF)")
fill(ema_8_plt, ema_21_plt, color=ema_8_high_res > ema_21_high_res ? color.new(color.lime, 70) : color.new(color.maroon, 70))

//--- Bollinger Keltner Squeeze
bgcolor((bb2_upper < k_upper) and (bb2_lower > k_lower) ? color.new(color.orange, 90) : na, title="Squeeze")

Overview

TVT BB Squeeze w/ 8 21 SMA/EMA calculates Bollinger Bands at two standard deviations alongside Keltner Channels to highlight squeeze conditions via background color changes. The script also requests 8-period and 21-period exponential moving averages from a specified higher timeframe, filling the area between them to display trend bias. User settings permit switching between EMA and SMA calculations, adjusting channel multipliers, and modifying the higher timeframe resolution.

Details

Published by

namuan on GitHub

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.

Topics

dtaleearnings-calendarmarket-analysisoptions-tradingstock-market-analysistelegram-bottrading-strategies

Settings

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

SettingTypeDefaultVariable
Lengthint21length
Sourcesourceclosesrc
Use EMA over SMA?booltrueuse_ema
Keltner Rangefloat2k_mult
Band 1 StDevfloat2.0bb2_mult
Band 2 StDevfloat3.0bb3_mult
High Res 8x21 EMA TFtimeframeDhigher_res
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

NVDA Trend Ribbon

by longsurf-ai
280 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated 4 weeks ago · MIT GitHub repository of NVDA Trend Ribbon

Bollinger Bands Force

by harryguiacorn
220 stars

This indicator modifies standard Bollinger Bands to measure directional trend force based on line alignment. It calculates a simple moving average basis along with upper and lower volatility bands. When all three lines move upward or downward simultaneously, i

Indicator v5 Volatility & bandsTrend
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Force

Adaptive MA Slope

by capissimo
114 stars

This indicator calculates Kaufman's Adaptive Moving Average (KAMA) on a chosen price source and determines trend direction based on the slope across a configurable lookback window. Signals can be filtered by short-term volatility expansion using ATR comparison

Indicator v4 Moving averagesTrend
Updated 2 years ago · None stated GitHub repository of Adaptive MA Slope

Adaptive Price Zone

by mihakralj
99 stars

The Adaptive Price Zone indicator calculates volatility bands around a double-smoothed exponential moving average baseline directly on the price chart. It calculates internal smoothing factors using the square root of the user-specified period, double-smoothin

Indicator v6 Volatility & bandsTrend
Updated 8 weeks ago · Apache-2.0 GitHub repository of Adaptive Price Zone

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