//@version=5
// Bollinger band squeeze + directional breakout. Fires when:
// - BB width is below its N-period mean (squeeze regime)
// - Price closes outside the band (squeeze release)
// Best for volatility-compression regimes (consolidating markets that
// then break out with momentum). Default tuned for FX timeframes.
//
// Schema target: TVAlert (services/tradingview-bridge/src/tradingview_bridge/schemas.py)
strategy(
title="bridge/04 - Bollinger squeeze",
shorttitle="04-BB",
overlay=true,
default_qty_type=strategy.percent_of_equity,
default_qty_value=10,
initial_capital=10000,
commission_type=strategy.commission.percent,
commission_value=0.02)
// === Inputs ===
length = input.int(20, "BB length", minval=2)
mult = input.float(2.0, "BB stdev", minval=0.5, step=0.1)
squeeze_lookback = input.int(50, "Squeeze lookback", minval=10)
squeeze_pct = input.float(0.7, "Squeeze threshold (width pct)", minval=0.1, maxval=1.0,
tooltip="Squeeze fires when current BB width < this fraction of the mean width over lookback")
ASSET_CLASS = input.string("fx", "Asset class",
options=["stock", "etf", "bond", "fx", "crypto", "prediction"])
STRATEGY_NAME = input.string("bollinger-squeeze-20", "Strategy name (for journal)")
SECRET = input.string("REPLACE_WITH_YOUR_TVBRIDGE_TV_WEBHOOK_SECRET", "Webhook shared secret")
// === Bands ===
basis = ta.sma(close, length)
dev = mult * ta.stdev(close, length)
upper = basis + dev
lower = basis - dev
width = upper - lower
plot(basis, "Basis", color=color.new(color.gray, 60))
plot(upper, "Upper", color=color.new(color.red, 30))
plot(lower, "Lower", color=color.new(color.green, 30))
// === Squeeze regime ===
mean_width = ta.sma(width, squeeze_lookback)
in_squeeze = width < (mean_width * squeeze_pct)
bgcolor(in_squeeze ? color.new(color.yellow, 85) : na)
// === Signals — squeeze release ===
long_signal = in_squeeze[1] and close > upper
short_signal = in_squeeze[1] and close < lower
// === Alert message ===
build_alert(action) =>
'{' +
'"alert_id":"' + STRATEGY_NAME + '-' + str.tostring(time, "yyyyMMdd-HHmm") + '-' + action + '",' +
'"secret":"' + SECRET + '",' +
'"strategy_name":"' + STRATEGY_NAME + '",' +
'"asset_class":"' + ASSET_CLASS + '",' +
'"symbol":"{{ticker}}",' +
'"action":"' + action + '",' +
'"size":"{{strategy.position_size}}",' +
'"size_type":"units",' +
'"price_hint":"{{close}}",' +
'"order_type":"market",' +
'"time":"{{time}}",' +
'"metadata":{"bb_width":"' + str.tostring(width, "#.####") + '","mean_width":"' + str.tostring(mean_width, "#.####") + '"}' +
'}'
if long_signal
strategy.entry("L", strategy.long, alert_message=build_alert("buy"))
if short_signal
strategy.entry("S", strategy.short, alert_message=build_alert("sell"))
Overview
Bridge 04 - Bollinger Squeeze draws upper, lower, and basis bands directly on the price chart while shading squeeze periods in yellow. A long position is triggered when price breaks above the upper band out of a squeeze, and a short position is opened on a breakout below the lower band. Settings allow customization of band length, deviation multiplier, squeeze threshold, and webhook alert payloads. The strategy lacks stop-loss or take-profit rules, exiting only upon opposite entry signals.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
BB length
int
20
length
BB stdev
float
2.0
mult
Squeeze lookback
int
50
squeeze_lookback
Squeeze threshold (width pct)
float
0.7
squeeze_pct
Asset class
string
fx
ASSET_CLASS
Strategy name (for journal)
string
bollinger-squeeze-20
STRATEGY_NAME
Webhook shared secret
string
REPLACE_WITH_YOUR_TVBRIDGE_TV_WEBHOOK_SECRET
SECRET
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.
This strategy plots VWMA-based Bollinger bands on the 1-minute ES futures price chart for volatility analysis and potential breakout identification. It calculates dynamic long and short stop loss and take profit levels using percentage inputs relative to entry
This strategy runs on the price chart and enters long when a fast simple moving average crosses above a slow one, and short on the opposite cross, while closing the other side. Entries also need ATR above a filter, a pullback check, a minimum candle-body chang
This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the
This trend-following strategy adapts classic Donchian breakout channels according to market volatility regimes. It calculates an ATR percentile rank across a rolling lookback period, shifting dynamically between tighter breakout channels with smaller stops dur
This strategy executes breakout trades using two Donchian Channels alongside an optional 200-period EMA trend filter. Entries trigger when the price sets a new highest high or lowest low over the primary Donchian Channel period. Exits are managed via a shorter
This strategy implements a channel breakout system directly on the main price chart. It calculates highest highs and lowest lows over configurable entry and exit periods using historical candles. A long entry triggers when the close breaks above the entry chan