WhitmanTrading

Bollinger Bands: The Formula Worked on 20 Real SPY Closes

Bollinger Bands are a moving average with a channel drawn two standard deviations above and below it, usually over 20 bars. The width of the channel measures recent volatility, so the bands widen when price is moving and narrow when it is quiet.

Bollinger Bands: The Formula Worked on 20 Real SPY Closes — illustrated on a chart Watch: Bollinger Bands for Beginners (Full Course)

Covered on this page: TradingView.

Bollinger Bands are three lines on a price chart: a 20-day simple moving average in the middle, and one line two standard deviations above it and one two below. The gap between the outer lines is a running measure of how much price has been moving.

This page does the arithmetic once by hand on twenty real SPY closes, then checks the two claims most guides make about the lines against 34,767 sessions of five exchange-traded funds.

How it works

John Bollinger built the tool in the 1980s, and the name has been a registered US trademark since 2011. The recipe has four steps, and every one of them uses the same twenty closing prices.

  1. Add the last 20 closes and divide by 20. That is the middle line, often called the basis.
  2. Subtract the basis from each close and square the result. Squaring makes every gap positive and weights the big ones more.
  3. Average those 20 squares, then take the square root. That is the standard deviation, in dollars.
  4. Upper line = basis + 2 × deviation. Lower line = basis − 2 × deviation.

Upper = SMA(20) + 2σ Lower = SMA(20) − 2σ σ = √( Σ(close − SMA)² / 20 )

Tomorrow the oldest close drops out of the window and a new one comes in, and all three lines are worked out again. That is why the channel can widen sharply after a single big day and then snap narrower twenty sessions later, when the same day leaves the window. Nothing in it uses highs, lows or volume.

A worked example: SPY’s 20 closes to 30 October 2026

These are SPY’s daily closes from Monday 5 October to Friday 30 October 2026, as Yahoo Finance recorded them. The average of the twenty is $770.468, so each row shows how far that close sat from it.

date close gap from basis gap squared
5 Oct $774.83 +$4.36 19.03
6 Oct $779.09 +$8.62 74.34
7 Oct $777.22 +$6.75 45.59
8 Oct $773.93 +$3.46 11.99
9 Oct $778.57 +$8.10 65.64
12 Oct $778.10 +$7.63 58.25
13 Oct $778.01 +$7.54 56.88
14 Oct $769.60 −$0.87 0.75
15 Oct $771.79 +$1.32 1.75
16 Oct $763.25 −$7.22 52.10
19 Oct $766.48 −$3.99 15.90
20 Oct $769.05 −$1.42 2.01
21 Oct $773.09 +$2.62 6.88
22 Oct $763.96 −$6.51 42.35
23 Oct $759.97 −$10.50 110.21
26 Oct $765.37 −$5.10 25.99
27 Oct $769.66 −$0.81 0.65
28 Oct $772.31 +$1.84 3.39
29 Oct $769.36 −$1.11 1.23
30 Oct $755.72 −$14.75 217.50

Basis. The closes add up to $15,409.36. Divided by 20, that is $770.47.

Deviation. The squared gaps add up to 812.43. Divided by 20, that is 40.62, and its square root is $6.37. Two deviations is $12.75.

The lines. Upper: $770.47 + $12.75 = $783.22. Lower: $770.47 − $12.75 = $757.72. The channel was $25.49 wide.

The last close. SPY finished 30 October at $755.72, two dollars under the lower line. That one day carries the biggest squared gap in the table, 217.50 of the 812.43 total, so the close that broke out of the channel also did the most to widen it. Price and band are measured from the same numbers, which is why a sharp day always drags the nearest line toward itself.

Each figure above is computed from the unrounded closes; the rows are rounded to the cent for reading. What SPY did after 30 October was not yet known when this was written, so the next sections look at what closes like it did across three decades instead.

Population or sample: the 33-cent question

Step 3 divides by 20. Spreadsheets offer two deviation functions, and in Excel STDEV.P divides by the count while STDEV.S divides by the count minus one. Wikipedia’s article states that Bollinger Bands use the first, the population version, and that is the one worked above.

On the same twenty SPY closes, dividing by 19 gives a deviation of $6.54 instead of $6.37, about 2.6% larger. The lines move out to $783.55 and $757.39, roughly 33 cents each. On that day the close sat outside under either formula, but on a day when price finishes a few cents from a line, the two versions can disagree about whether it closed outside at all. If your spreadsheet and your charting platform never quite match, check this divisor first.

%B and BandWidth from the same numbers

Bollinger published two readings that turn the picture into a number, and both fall straight out of the example.

%B places the close inside the channel: (close − lower) ÷ (upper − lower). A reading of 1 is on the upper line, 0 is on the lower, 0.5 is the basis. For 30 October: ($755.72 − $757.72) ÷ $25.49 = −0.08. A negative %B is simply a close below the lower line, and a reading above 1 is a close over the upper one.

BandWidth is the channel’s width as a share of the basis: (upper − lower) ÷ basis. For 30 October: $25.49 ÷ $770.47 = 0.0331, or 3.31%.

The ratio matters because a $25 channel would be enormous on a $40 stock and tiny on a $4,000 index. With the default settings it equals four times the coefficient of variation, and its lowest readings in months are what traders call a Bollinger squeeze.

Changing the 20 and the 2

The defaults are a starting point, and the two numbers do different jobs. The 20 sets how much history the line remembers. The 2 sets how far out the lines sit, and so how often a close lands beyond them.

Bollinger’s own rules say the multiplier should rise with the length to keep the same share of prices inside: about 1.9 at 10 periods and 2.1 at 50. Fidelity’s indicator guide lists a different trio for short, medium and long horizons: 10 days at 1.5, 20 at 2, and 50 at 2.5. Those are wider apart than Bollinger’s pairs, so two charts both labeled “50-day Bollinger” can show different lines.

Whatever you pick, fix it before you look at the chart you want to judge. Turning the multiplier until the bands touch the turns you remember is fitting a drawing, as the technical analysis page explains, and it says nothing about the next turn. The middle line behaves like any other moving average, so its lag at 20 days is the same lag you would get without the bands.

The original data

What we measured. Daily closes for SPY (from January 1993), DIA (1998), QQQ (1999), IWM (2000) and GLD (2004), all to 30 October 2026, with 20-day, two-deviation bands built exactly as in the worked example. That gives 34,767 sessions with a full window. Each row, with its bands and the close ten sessions later, is in the published Bollinger Band file.

How often a close lands inside. Across all five funds, 88.78% of closes finished between the lines. The funds ranged from 87.26% (GLD) to 89.27% (SPY). That agrees with the 88-89% StockCharts quotes, and it is well below the 95.45% a normal distribution would put inside two deviations, because daily price changes have fatter tails and cluster in time.

What a close outside did next. The common reading is that the upper line is stretched and the lower one is cheap. To test it, we took each fund’s first close above the upper line after at least ten sessions without one, so the events do not overlap: 727 of them. Ten sessions later the fund was higher 57.22% of the time.

Over every session in the same data that had ten more sessions after it, 34,717 of them, the figure was 58.33%. The first closes under the lower line, 640 of them, were followed by a higher close 57.97% of the time.

Is that difference real? With 727 events, one standard error on the 58.33% base is about 1.83 percentage points, and the upper-line result sits about 0.6 of one below it. The lower-line result is closer still.

In plain terms: neither line told you anything about the next ten sessions that a coin weighted like an average day would not. That is what Bollinger’s own sixth rule says in words, that a tag of a band is not a signal by itself.

Horizontal bars comparing how often five ETFs closed higher ten sessions later: 58.33% across all 34,717 sessions, 57.22% after 727 first closes above the upper line, 57.97% after 640 first closes below the lower line.
Share of cases where the close 10 sessions later was higher: every session, then after a first close above or below the 20-day, two-deviation range, SPY, QQQ, IWM, DIA and GLD daily closes to 30 Oct 2026. Source: Yahoo Finance (m108-bollinger-20-2-closes-outside-and-10-day-after-5-etfs.csv).

What a close above tends to be followed by. Counting every close above the upper line, not only the first, 1,227 of 2,027 (60.53%) had another close above within the next five sessions. That is the pattern StockCharts calls walking the bands: in a strong move the line keeps rising underneath price.

GLD gave a clean case in January 2026. It closed above its upper line on eight straight sessions, 20 to 29 January, climbing from $437.23 to $495.90, a rise of 13.42%. Every one of those closes looked stretched, and selling the first would have missed the run.

Then on 30 January it closed at $444.95, down 10.27% in a single session and back inside the channel. The chart also shows four shorter tags in late December and one on 12 January, each followed by a drift back inside. Both halves belong in the lesson: the walk was long, and it ended without warning from the bands.

GLD daily closes from December 2025 to February 2026 with the 20-day basis and upper and lower Bollinger lines, 13 dots on closes above the upper line, eight of them in a row from 20 to 29 January.
GLD daily closes with the 20-day basis and the two-deviation upper and lower lines, 1 Dec 2025 to 27 Feb 2026 (61 sessions); dots mark the 13 closes above the upper line. Source: Yahoo Finance (m108-bollinger-20-2-closes-outside-and-10-day-after-5-etfs.csv).

The video study. Across our study of 24,971 trading videos, 268 carry Bollinger in the title. The median one gets 4,842 views, 82% never pass 50,000, and the median length is 9.2 minutes.

That saturation is high but not the highest measured here: Chaikin money flow sits at 96% and Hull moving averages at 92%. Description text exists for 72 of the 268, and 4 of those 72 mention invalidation, failure or what a bad read looks like.

When it fails

Treating the outer lines as a ceiling and a floor

The 727 first closes above the upper line went on to rise about as often as any day did. A line drawn from the last twenty closes moves up with a rising market, so a close near it is ordinary in a trend. The same holds for the lower line in a fall. If you want to know how a buy-the-lower-line rule fared once costs and holding were counted, the Bollinger Band bounce page backtests one.

Reading direction into a narrow channel

Low BandWidth says the last twenty closes were quiet. It does not say which way the next move goes, and a quiet spell can resolve either way or simply stay quiet. The trading range page reads the same condition off highs and lows instead of arithmetic, and the breakout page measures how often the move out of one fails.

One old day leaving the window

Because every close in the window counts equally, a big day 19 sessions ago props the lines open until the day it drops out. The channel can then shrink overnight with nothing new happening, which looks like a change in the market and is only a change in the window.

Settings that don’t match

Population or sample divisor, a 20 or a 21 window, closes or typical price as the input: any of these moves the lines by cents to dollars. Before you compare a level from one platform with another, check all three.

Questions people ask

What do Bollinger Bands tell you?

How far the current close sits from its 20-day average, measured against how much the last 20 closes have varied. Wide lines mean recent prices were spread out; narrow ones mean they were bunched. They do not say what comes next.

Is a close above the upper band a sell signal?

Not on the evidence above. On five ETFs, the first close above the upper line was followed by a higher close ten sessions later 57.22% of the time, against 58.33% for every session, a gap well inside chance.

What are the best Bollinger Band settings?

There is no best pair, only a consistent one. The 20-period average with 2 deviations is the default on most platforms. Bollinger suggests about 1.9 deviations at 10 periods and 2.1 at 50 if you change the length.

Do Bollinger Bands use population or sample standard deviation?

Population, dividing by the number of closes in the window. On SPY’s 20 closes to 30 October 2026 the sample version would have put each line about 33 cents further out.

Moving average is the middle line, and most of what is true of it is true here.

How to use Bollinger Bands walks through setting them up and reading them step by step.

For the tools these get set against: Bollinger Bands vs Keltner Channels swaps the deviation for average true range, Bollinger Bands vs ATR asks which one sizes a stop, and Bollinger Bands vs standard deviation looks at the raw number before it is drawn. Range expansion, CCI, price action and support and resistance read the same volatility and stretch in other ways.

The practical check

The most useful thing these give you is the width, because it shows something hard to see otherwise: whether the last twenty bars were quiet or wild. Do not fade the bands. Selling every touch of the upper band loses money in a strong trend, because in a trend closing near the top of the recent range is the normal condition, not an extreme.

— Michael Whitman

This page is educational, not financial advice. Test every idea on your own charts before risking money. Some links on this page earn a commission if you buy through them. It costs you nothing and it does not decide what appears here or in what order — how these pages are made is set out in our methodology.