# What are Bollinger Bands? %B, bandwidth, formula and example

Canonical URL: https://marketheist.io/portfolio/learn/bollinger-bands
By Jeffrey Lin · Published 2026-11-20 · Updated 2026-11-20 · Data through Sep 2026
Category: Indicators

## Key takeaways

- Bollinger Bands draw a channel around a moving average whose width follows recent volatility: wide after turbulent weeks, narrow after quiet ones.
- %B turns the picture into one number: zero at the lower band, one at the upper band, a half at the middle line. Below zero or above one, the close is outside the bands.
- A close above the middle line is the same as a close above the 20-day average, so a %B rule at one half is a short-term trend rule. A touch of an outer band can be read as a stretched price or as a breakout, and the bands alone do not say which.
- Bandwidth, the distance between the bands relative to the average, measures volatility. A very narrow band, the squeeze, has often come before a large move, in either direction.
- MarketHeist's bands come out a touch wider than in Bollinger's own definition because of how the standard deviation is computed; the How MarketHeist computes it section gives the detail.

## Definition

Bollinger Bands, created by John Bollinger in the 1980s, are a moving average with bands a set number of standard deviations above and below it, by default a 20-day simple average and two standard deviations, so the bands widen when prices swing more and narrow when they calm down. %B expresses where the latest close sits relative to the bands: 0 at the lower band, 1 at the upper band and 0.5 at the middle.

Also known as: Bollinger Bands, %B, percent B, Bollinger %B, Bollinger bandwidth, Bollinger squeeze, 20-day 2 standard deviation bands, volatility bands.

## How it works

Start with the 20-day simple moving average of the close: the middle band. Measure how much the last twenty closes are spread around it, using their standard deviation. Add two standard deviations to the average for the upper band and subtract two for the lower band. When prices have been swinging, the standard deviation is large and the bands are wide; when they have been quiet, the bands close in.

%B places the latest close on that scale. At the lower band it is 0, at the upper band 1, at the middle line 0.5, and it goes below 0 or above 1 when the close is outside the bands. Because the middle of the bands is the 20-day average, a %B above 0.5 means exactly that the close is above its 20-day average. Bandwidth is the distance between the bands divided by the middle band, a measure of recent volatility relative to price.

Bollinger Bands are like guard rails set farther apart where the road twists: the rails do not show where the road goes next, only how far the car has strayed from the middle compared with how twisty the road has been.

Readings at the bands are used both ways. A close below the lower band can be a stretched price that tends to snap back, the mean-reversion reading, or the start of a decline, and a close above the upper band can be overbought or a breakout. Bollinger himself warned against treating a band touch as a signal on its own and suggested confirming it with other indicators. Prices are not normally distributed, so the share of closes outside the bands varies with the asset and the period.

The squeeze is the pattern most associated with the bands: after a stretch of unusually low volatility the bands are at their narrowest, and a large move has often followed. The bands do not say which way that move goes, and a squeeze can last longer than a trader expects.

## Formula

**Bands, %B and bandwidth**

```
M_t = \frac{1}{n} \sum_{j = 0}^{n - 1} C_{t - j}, \sigma_t = \sqrt{\frac{1}{n - 1} \sum_{j = 0}^{n - 1} (C_{t - j} - M_t)^2}, U_t,D_t = M_t \pm k \sigma_t
```

where:

- Cₜ: adjusted close on day t
- n: window: 20 by default
- k: band width in standard deviations: 2 by default
- j: days back from day t, from 0 to n − 1
- Mₜ: middle band, the n-day simple moving average
- σₜ: sample standard deviation of the last n closes
- Uₜ, Dₜ: upper and lower bands

Bollinger defines σ with the population divisor n; MarketHeist divides by n − 1, which widens the bands by √(n ÷ (n − 1)), a factor of about 1.026 at n = 20.

**%B and bandwidth**

```
%B_t = \frac{C_t - D_t}{U_t - D_t} = 0.5 + \frac{C_t - M_t}{2 k \sigma_t}, BW_t = \frac{U_t - D_t}{M_t}
```

where:

- %Bₜ: where the close sits between the bands: 0 at the lower, 1 at the upper
- BWₜ: bandwidth: the bands' distance relative to the middle band

The second form shows that %B is a rescaled z-score of the close against its 20-day average, and that %B > 0.5 exactly when the close is above the middle band. MarketHeist sets %B to 0.5 when the bands have zero width.

## Worked example

SPY's daily bars from Oct 2006 to Sep 2026, about 20 years, with 20-day, two-standard-deviation Bollinger Bands and three %B rules, each acted on with the standard one-bar delay, no trading costs and no interest on cash.

SPY's %B had a median of 0.69 over the window, and on four days in five it sat between 0.12 and 0.94: in a market that rose over most of these years, the close spent more days above its 20-day average than below it.

The default rule, long while %B is above 0.5, which amounts to the close being above its 20-day average, held SPY on 66.7% of days and completed 285 round trips, 14.3 a year. It grew 4.8% a year against 11.1% for holding SPY, with a worst decline of -37.1% against -55.2%.

Buying closes below the lower band, a bet on a snap-back, held SPY on only 4.9% of days, in 139 trades lasting 1.8 days on average; 74.1% of them ended with a gain, and the rule grew 4.2% a year. Holding only closes above the upper band, the breakout reading, was invested on 4.2% of days, in 132 trades, and its growth rate was -0.2% a year.

None of the three rules grew as fast as holding SPY over this window. The bands measure how far the price has stretched relative to its own recent volatility; on their own, on this fund and these years, they did not separate the moves that continued from the moves that reversed.

Data through Sep 2026. Reproduce id: c4ede62ebb590931 (this guide, its lab setup and the data month).

## How MarketHeist computes it

- **Data**: Daily bars (open, high, low, close, volume) of the fund as the MarketHeist data service serves them to the backtester: prices adjusted for splits and dividends, so a dividend counts as reinvested. They come from a snapshot taken each month and cut at the data month of this page, and are not rounded. The fund's own history, not an extension: a fund younger than the window is measured over the years it has.
- **Window**: The worked example and the lab measure the last 20 years of trading days, Oct 2006 to Sep 2026 (5030 days), ending at the data month of this page. Every setup, and buy and hold, is measured over exactly these days; an indicator is warmed up on the days before them, so changing a setting never moves the window, and a setting that needs more history than exists before the window is refused rather than measured over fewer days.
- **Backtest**: The backtester's own engine, in the order it runs it: the indicator, the position rule (or entry and exit triggers) and the optional regime filter produce a position for every day of the fund's whole history; the position is then shifted forward by the execution delay and applied to each day's return over the window. Cash earns 0, there is no leverage, and a one-way cost in basis points is charged on the size of every change of position. Round trips are the closed entries of the trade log (a trade still open on the last day is not counted); the win rate is the share of them with a gain; the payoff ratio is the average win over the size of the average loss; expectancy is the average return per trade; the per-trade profit factor is the sum of the winning trades' returns over the size of the sum of the losing ones, while the per-day profit factor sums days.
- **Years and volatility**: A year is 252 trading days, the engine's convention: trades per year is round trips over days divided by 252, the CAGR is the growth multiple to the power 252 over the days, and volatility is the sample standard deviation of the daily returns times the square root of 252.
- **Indicator statistics**: The indicator's main output over the window: its last value, its 10th, 50th and 90th percentile (linear interpolation between ranks), and the share of days the rule alone says long, before the delay and any regime filter. Every output of the indicator is also summarized by its median and the share of days below 0.
- **Buy and hold**: The fund held every day of the window with dividends reinvested. The largest one-day gain and loss are the highest and lowest daily returns; the CAGR without the 10 or 30 largest gains (or losses) replaces those days' returns with 0 and recompounds.
- **Middle band**: Simple moving average of the adjusted close over the window (default 20, range 5 to 300), the current close included. (`sma` in packages/shared/engine/utils.ts)
- **Standard deviation**: Sample standard deviation (divides by n − 1, as pandas rolling std) of the same closes, two-pass. Bollinger's definition uses the population form (divides by n), so these bands are wider by √(n ÷ (n − 1)): about 2.6% at 20 days. Platforms that follow Bollinger show slightly narrower bands. (`rollingStd` in packages/shared/engine/utils.ts)
- **%B and bandwidth**: %B = (close − lower) ÷ (upper − lower), 0.5 when the bands have zero width; bandwidth = (upper − lower) ÷ middle. %B is the primary output that position rules read; bands and bandwidth are chart outputs. (`compute` in packages/shared/engine/indicators/bollinger.ts)
- **Defaults**: Window 20, two standard deviations (range 0.5 to 4 in steps of 0.1); default rule long while %B is above 0.5, the close above its 20-day average. (`SPEC` in packages/shared/engine/indicators/bollinger.ts)
- **Engine functions**: `computePosition` (packages/shared/engine/run_basic.ts), `generatePosition` (packages/shared/engine/positions.ts), `applyRegimeFilter` (packages/shared/engine/regime_filter.ts), `generateTriggeredPosition` (packages/shared/engine/triggered_position.ts), `runBacktest` (packages/shared/engine/backtest.ts), `getIndicator` (packages/shared/engine/indicators/registry.ts)

## Bollinger Bands and %B compared with its neighbours

Bollinger %B and related measures

| Measure | Centre | Width set by | Reads |
| --- | --- | --- | --- |
| Bollinger %B | 20-day simple average of the close | Standard deviation of closes | 0 at the lower band, 1 at the upper |
| Z-score of the close | Moving average | Standard deviation | Standard deviations from the average; %B rescaled |
| Keltner channel | Exponential average | Average true range | Bands that follow daily ranges instead of closes |
| CCI | Average typical price | Mean absolute deviation | Unbounded; ±100 as Lambert's band |
| Stochastic %K | None: the recent high-low range | Highest high and lowest low | 0 to 100 within the range |

## Limitations

- The bands describe the past twenty days; a close outside them is unusual only relative to that short window, and volatility regimes change quickly.
- Band touches are read both as reversal and as breakout signals. Any rule that picks one reading is a hypothesis to test, not a property of the bands.
- The example charges no trading costs. The middle-line rule trades often enough that costs change its result materially.
- Bands built with the sample standard deviation are slightly wider than Bollinger's population definition, so band touches differ a little from some charting platforms.
- One fund over one window that rose for most of its length; the same rules behave differently on assets that trend down or range for years.

## Frequently asked questions

**What does %B mean in Bollinger Bands?**

%B says where the close sits relative to the bands: 0 at the lower band, 1 at the upper band, 0.5 at the middle line. Negative values and values above 1 mean the close is outside the bands.

**What is the Bollinger squeeze?**

A period when the bands are unusually close together because recent volatility is low. It has often preceded a large move, but the squeeze itself says nothing about the direction of that move.

**Do prices stay inside Bollinger Bands most of the time?**

Usually, yes, but how often depends on the asset and the period. The common statement that a fixed share of closes falls inside two standard deviations assumes normally distributed prices, which markets do not have; closes outside the bands cluster in volatile stretches.

**Why do MarketHeist's bands differ slightly from another platform's?**

MarketHeist computes the standard deviation with the sample divisor, which makes the bands very slightly wider than Bollinger's population definition, and it uses dividend-adjusted closes. Both effects are small but can move a borderline band touch.

**Is a close above the upper band a sell signal?**

Not by itself. A close above the upper band means the price rose unusually fast for its recent volatility; in a strong trend that can continue for weeks. Bollinger suggested confirming band signals with other indicators.

## References

1. Bollinger, J. (2001) Bollinger on Bollinger Bands. McGraw-Hill. The bands, %B, bandwidth and the squeeze, by their creator.
2. Murphy, J. J. (1999) Technical Analysis of the Financial Markets. New York Institute of Finance. Bollinger Bands among envelope and channel indicators.

## Try it

App: https://marketheist.io/backtest/?c=eyJ0aWNrZXIiOiJTUFkiLCJmcmVxdWVuY3kiOiIxZCIsImluZGljYXRvcl9pZCI6ImJvbGxpbmdlciIsImluZGljYXRvcl9wYXJhbXMiOnsid2luZG93IjoyMCwibnVtX3N0ZCI6Mn0sInBvc2l0aW9uX3J1bGUiOnsidHlwZSI6InRocmVzaG9sZCIsInRocmVzaG9sZCI6MC41LCJkaXJlY3Rpb24iOiJhYm92ZSJ9LCJleGVjdXRpb25fZGVsYXkiOjEsInRyYW5zYWN0aW9uX2Nvc3RzX2JwcyI6MCwibGV2ZXJhZ2UiOnsibW9kZSI6Im5vbmUifX0

MCP prompt (MarketHeist MCP server, https://marketheist.io/mcp):

```
Using MarketHeist.io, backtest Bollinger %B (20 days, 2 standard deviations) on SPY daily bars with execution delay 1 three ways: long while %B is above 0.5, long only while %B is below 0, and long only while %B is above 1. Compare time in the market, trades, CAGR and max drawdown with buy-and-hold.
```

Historical simulation, not advice.
