Bollinger BandWidth Indicator: TradingView Pine Script for Volatility and Squeeze Trading
Watching price coil inside narrowing Bollinger Bands and wondering when the next big move will start is something every volatility trader runs into. I've found that the Bollinger BandWidth (BBW) indicator takes the guesswork out of that. Instead of eyeballing band squeeze on the chart, BBW gives you a single line that measures band width as a percentage of the middle band—so you can see exactly when volatility is contracting and when it's about to expand.
BandWidth doesn't predict direction by itself, but it does tell you when conditions are ripe for a breakout. When BBW drops toward its lowest levels (a squeeze), volatility has compressed; when it starts to rise again, the bands are widening and price often makes a decisive move. Pairing BBW with the actual Bollinger Bands on price helps you time entries instead of chasing. In this guide you'll see how BBW is calculated, how to add and tune it in TradingView (including via Pineify), and how to use it in real strategies with clear entry, stop-loss, and take-profit rules.
What is Bollinger BandWidth?
Bollinger BandWidth is a volatility oscillator derived from Bollinger Bands. It measures how wide the bands are relative to the middle band (the basis), expressed as a percentage. When the bands widen, BBW rises; when they contract (a squeeze), BBW falls.
The formula is:
BBW = (Upper Band − Lower Band) / Basis × 100
Where:
- Basis is the simple moving average (SMA) of your chosen source (usually close).
- Upper Band = Basis + (Multiplier × Standard Deviation of source).
- Lower Band = Basis − (Multiplier × Standard Deviation of source).
So BBW is just the band width as a percentage of the middle line. There are no fixed overbought/oversold levels; what matters is whether BBW is high (wide bands, high volatility) or low (narrow bands, low volatility). Many implementations also plot the highest BBW over the last N bars (Highest Expansion) and the lowest BBW over the last N bars (Lowest Contraction), so you can see recent volatility extremes at a glance.
Widening bands suggest increasing volatility and often accompany strong trends or breakouts. Narrowing bands suggest a squeeze—volatility has dried up and a breakout is more likely when BBW starts to expand again. That’s why BBW is often used with Bollinger Bands to time breakouts from squeeze-style setups rather than to trade reversals on its own.
How to Add Bollinger BandWidth to TradingView
TradingView doesn’t ship a built-in “Bollinger BandWidth” by name, but you can add it in two ways:
Option 1 – Pineify (recommended)
- Open Pineify and open the Pine Script editor.
- Search for “Bollinger BandWidth” or “BBW” in the indicator library.
- Add the indicator to your layout and adjust inputs (length, source, std dev, expansion/contraction lookback).
- Copy the generated Pine Script into TradingView’s Pine Editor and add it to your chart.
Option 2 – TradingView Pine Editor
- In TradingView, open the Pine Editor and paste a Bollinger BandWidth script (e.g. from the community or the one in this article).
- Click “Add to chart.” The indicator will appear in a separate pane under the chart.
- Open the indicator settings (gear icon) to change length, source, multiplier, and the lengths used for Highest Expansion and Lowest Contraction.
Typical inputs are: Length (e.g. 20), Source (close), StdDev (2), Highest Expansion Length (e.g. 125), and Lowest Contraction Length (e.g. 125). The whole process with Pineify usually takes about five minutes including customization.
How to Use Bollinger BandWidth (Practical Trading Strategies)
BBW is best used to filter or time trades rather than as a standalone buy/sell signal. Below are concrete ways to use it.
Strategy #1: Squeeze breakout (direction from price or another indicator)
- Setup: BBW has been low (squeeze); price is range-bound inside Bollinger Bands.
- Entry: BBW turns up from a recent low (bands start to widen) and price breaks out of the range (e.g. above the upper band for longs or below the lower band for shorts). Confirm direction with trend or momentum if you like.
- Stop-loss: Under the breakout candle’s low (longs) or over its high (shorts), or under/over the recent range.
- Take-profit: First meaningful resistance/support, or a multiple of the initial risk (e.g. 1.5–2R).
Strategy #2: Mean reversion after expansion
- Setup: BBW has risen to a relatively high level (bands wide); price has stretched to the upper or lower band.
- Entry: Look for a reversal sign (e.g. rejection candle, divergence) near the band. BBW staying high confirms volatility is present; you’re fading the stretch.
- Stop-loss: Beyond the recent extreme (above the high for shorts, below the low for longs).
- Take-profit: Middle band (basis) or the opposite band.
Strategy #3: Trend continuation with volatility confirmation
- Setup: Clear trend (e.g. higher highs/higher lows).
- Entry: On a pullback in the trend, wait for BBW to be rising or at least not at a multi-bar low when price finds support/resistance (e.g. at a moving average or band). Enter in the trend direction when price resumes.
- Stop-loss: Below the pullback low (longs) or above the pullback high (shorts).
- Take-profit: Next logical target or trail with a moving average / ATR.
I’ve found combining BBW with the actual Bollinger Bands on price keeps entries clearer: use BBW to confirm that volatility is expanding (or that a squeeze is ending) and use the bands and price action for exact entry and stop placement.
Best Bollinger BandWidth Settings
Settings should match your timeframe and style. Below are practical starting points.
Scalping (1–5 minute charts)
- Length: 10–15 (faster reaction).
- StdDev: 1.5–2.
- Highest Expansion / Lowest Contraction: 30–50 bars.
- Shorter lookbacks keep the “highest/lowest” lines relevant to recent volatility.
Day trading (15–60 minute charts)
- Length: 20 (standard).
- StdDev: 2.
- Expansion/Contraction length: 50–100.
- Balances noise and squeeze/expansion visibility.
Swing trading (4H–daily charts)
- Length: 20–30.
- StdDev: 2.
- Expansion/Contraction length: 100–125.
- Longer lookbacks help spot meaningful squeezes and expansions.
Position trading (daily/weekly)
- Length: 20–30.
- StdDev: 2–2.5.
- Expansion/Contraction length: 125 or more.
- Focus on major volatility cycles.
In general: shorter length and shorter expansion/contraction periods make BBW more sensitive; longer values smooth it and emphasize bigger squeezes and expansions.
Advanced Bollinger BandWidth Techniques
Multi-timeframe use
Check BBW on a higher timeframe (e.g. daily) for squeeze/expansion, then use the lower timeframe (e.g. 4H or 1H) for exact entry when BBW starts to rise and price breaks.
Combining with other indicators
- RSI: Use RSI for overbought/oversold at band touches; use BBW to confirm volatility context (e.g. only take reversals when BBW is high).
- Volume: Require above-average volume on BBW expansion breakouts for conviction.
- Bollinger Bands on price: Use BBW to confirm squeeze and expansion; use band touches and breakouts for entries.
Risk and pitfalls
- BBW does not show direction; always pair with price structure or another indicator for side (long/short).
- A rising BBW can mean a strong trend or a sharp reversal; context (trend, key levels) matters.
- Avoid using BBW alone in choppy, low-liquidity markets without additional filters.
How to Backtest Bollinger BandWidth
Backtesting helps you see if your BBW-based rules add value before risking capital. In the Pineify Editor you can build a strategy that uses BBW in the conditions and then backtest it.
Typical strategy elements:
- Entry/exit conditions: e.g. BBW rising from a low + price breaking a band or a range; optionally filter by trend.
- Market orders: long/short when conditions are met.
- Take profit: fixed target, or band/level-based.
- Stop loss: below/above breakout candle or recent swing.
- Trailing stop (optional): to lock in profits when volatility expands in your favor.
Risk management:
- Risk 1–2% of capital per trade (position size so that stop distance equals 1–2% of account).
- Limit how many concurrent positions you have.
- Test on multiple symbols and timeframes to see where the edge holds.
No indicator works every time; backtesting shows whether your BBW setup has a positive expectancy and in which markets/timeframes it works best.
FAQs
What is the best length for Bollinger BandWidth?
20 is the most common and works well for swing and day trading. Use 10–15 for scalping and 25–30 for longer timeframes. Match it to the length you use for Bollinger Bands on price if you use both together.
Can I use Bollinger BandWidth for crypto?
Yes. Crypto is volatile, so BBW often reaches higher peaks and deeper squeezes. Use the same logic: trade expansion from squeezes and consider slightly shorter lengths (e.g. 15–20) on lower timeframes. Always use stops and size appropriately.
How do I avoid false breakouts when BBW expands?
Wait for a clear bar close beyond the band or range, require volume confirmation, and consider only taking breakouts in the direction of the higher-timeframe trend. Combining BBW with Bollinger Bands and price structure reduces false signals.
What is the difference between Bollinger BandWidth and Bollinger %B?
BandWidth measures how wide the bands are (volatility). %B measures where price is inside the bands (e.g. 0 = lower band, 1 = upper band). BBW is for squeeze/expansion; %B is for overbought/oversold within the bands. They complement each other.
Should I use Highest Expansion and Lowest Contraction lines?
They help you see recent volatility extremes without scanning the whole history. Use them as context: when BBW is near the Lowest Contraction line, you’re in a squeeze; when it approaches the Highest Expansion line, volatility has been high. Default lengths around 100–125 work for most timeframes.
Can I combine Bollinger BandWidth with RSI or MACD?
Yes. Use BBW for volatility context (squeeze vs expansion) and RSI or MACD for momentum and direction. For example: only take long breakouts when BBW is expanding and RSI or MACD confirms momentum. Keep the rule set simple so backtests stay interpretable.
BBW works best when you combine it with price structure and other indicators, and when you test your rules on a demo or small size before going live. Key takeaways:
- Use BBW to spot squeezes (low width) and volatility expansion (rising width), not direction by itself.
- Pair it with Bollinger Bands on price and, if you like, RSI or volume for entries and filters.
- Match length and expansion/contraction settings to your timeframe and style.
- Backtest with clear entry, stop-loss, and take-profit rules and 1–2% risk per trade.
- Test on a demo or small size before going live.



