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

On this page

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
Mt=1n∑j=0n−1Ct−j,σt=1n−1∑j=0n−1(Ct−j−Mt)2,Ut,Dt=Mt±kσt
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
%Bt=Ct−DtUt−Dt=0.5+Ct−Mt2kσt,BWt=Ut−DtMt
%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).

Interactive lab

SPY's price inside its Bollinger Bands with the days invested shaded, %B with the rule's line, and the results table for the middle-line, lower-band and upper-band rules against buy-and-hold. Change the window, the band width, the level, the direction, the cost or the fund.

SPY price with the days the base rule held itS&P 500, adjusted daily close, Oct 2006 to Sep 2026, log scale. Shaded: the 286 stretches the base rule held the fund (67% of 5030 days). Also drawn: Upper band, Lower band.$50$100$200$50020062011201620212026SPY adjusted closeUpper bandLower bandHeld by the base rule
SPY on a log scale. Shaded: the days the base rule held the fund. Oct 2006 to Sep 2026.
Bollinger %B with the base rule's lineBollinger %B on SPY, Oct 2006 to Sep 2026. The rule compares it with the fixed line 0.5.-0.4-0.200.20.40.60.811.2200620112016202120260.5Bollinger %B
Bollinger %B and the line the base rule compares it with. Oct 2006 to Sep 2026.
Growth of $10,000: the setups against buy and holdS&P 500, Oct 2006 to Sep 2026, log scale. $10,000 grows to $25,370 (base), $22,886 (Below the lower band: %B below 0), $9,564 (Above the upper band: %B above 1), $82,292 (buy and hold).$10k$20k$50k20062011201620212026Base ruleBelow the lower band: %B below 0Above the upper band: %B above 1Buy and hold
Growth of $10,000 on a log scale, same days for every line. Oct 2006 to Sep 2026.
MeasureBaseBelow the lower band: %B below 0Above the upper band: %B above 1Buy and hold
CAGR4.8%4.2%-0.2%11.1%
Volatility (annualized)11.3%7.8%1.9%19.4%
Maximum drawdown-37.1%-15.5%-9.5%-55.2%
Sharpe ratio0.470.57-0.110.64
Sortino ratio0.641.05-0.14n/a
Growth of $10,000$25,370$22,886$9,564$82,292
Time in the market66.7%4.9%4.2%100.0%
Round trips285139132n/a
Round trips per year14.37.06.6n/a
Win rate35.1%74.1%50.8%n/a
Average win3.5%1.2%0.4%n/a
Average loss-1.3%-1.2%-0.5%n/a
Payoff ratio2.691.040.82n/a
Average days held11.71.81.6n/a
Expectancy per trade0.4%0.6%-0.0%n/a
Profit factor, per day1.111.690.901.13
Profit factor, per trade1.462.970.86n/a
Indicator, last day0.4410.4410.441n/a
Indicator, 10th / 50th / 90th percentile0.118 / 0.69 / 0.940.118 / 0.69 / 0.940.118 / 0.69 / 0.94n/a
Days the rule alone is long66.6%4.9%4.2%n/a

S&P 500, Oct 2006 to Sep 2026, 5030 trading days. Every setup is measured over the same days, with the indicator warmed up on earlier ones; cash earns 0. Base: Bollinger Bands (%B) (window 20, num std 2); long while the Bollinger %B is above 0.5; execution delay 1; cost 0 bps one way. Below the lower band: %B below 0: Bollinger Bands (%B) (window 20, num std 2); long while the Bollinger %B is below 0; execution delay 1; cost 0 bps one way. Above the upper band: %B above 1: Bollinger Bands (%B) (window 20, num std 2); long while the Bollinger %B is above 1; execution delay 1; cost 0 bps one way.

Buy and hold, same daysValue
Largest one-day gain14.5% on 13 Oct 2008
Largest one-day loss-10.9% on 16 Mar 2020
CAGR without the 10 largest gains6.6%
CAGR without the 30 largest gains1.8%
CAGR without the 10 largest losses16.0%
CAGR without the 30 largest losses22.1%

The days replaced by 0 are the largest daily gains (or losses) of the window.

How MarketHeist computes it

Every choice an implementation has to make, as the code makes it today. The page is checked against the code each time it is built.

ChoiceHow it is computedIn the code
DataDaily 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.
WindowThe 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.
BacktestThe 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 volatilityA 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 statisticsThe 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 holdThe 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 bandSimple moving average of the adjusted close over the window (default 20, range 5 to 300), the current close included.smapackages/shared/engine/utils.ts
Standard deviationSample 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.rollingStdpackages/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.computepackages/shared/engine/indicators/bollinger.ts
DefaultsWindow 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.SPECpackages/shared/engine/indicators/bollinger.ts
Engine functionsThe functions the portfolio app and the MarketHeist MCP tools run, called here on the same monthly returns.computePositionpackages/shared/engine/run_basic.tsgeneratePositionpackages/shared/engine/positions.tsapplyRegimeFilterpackages/shared/engine/regime_filter.tsgenerateTriggeredPositionpackages/shared/engine/triggered_position.tsrunBacktestpackages/shared/engine/backtest.tsgetIndicatorpackages/shared/engine/indicators/registry.ts

Bollinger Bands and %B compared with its neighbours

Bollinger %B and related measures
MeasureCentreWidth set byReads
Bollinger %B20-day simple average of the closeStandard deviation of closes0 at the lower band, 1 at the upper
Z-score of the closeMoving averageStandard deviationStandard deviations from the average; %B rescaled
Keltner channelExponential averageAverage true rangeBands that follow daily ranges instead of closes
CCIAverage typical priceMean absolute deviationUnbounded; ±100 as Lambert's band
Stochastic %KNone: the recent high-low rangeHighest high and lowest low0 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 on your own holdings

Open Bollinger %B in the backtester →

Or ask an assistant connected to the MarketHeist MCP server (https://marketheist.io/mcp), which computes the same figures:

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.

Ask an AI assistant

The prompt opens in a new tab, already filled in. An assistant without the MarketHeist connector answers from its own knowledge, not from the figures on this page.

Historical simulation, not advice. Computed by the MarketHeist portfolio engine from monthly total returns, data through Sep 2026. Markdown version of this page: bollinger-bands.md.