standarddeviationcalculator.net

Updated

Bollinger Bands and the rolling standard deviation

Bollinger Bands are three lines drawn over a price chart: a moving average, and a band two standard deviations above and below it. The standard deviation is not fixed. It is recalculated at every step from the most recent prices, which is why the bands widen and narrow as the market calms down or gets agitated.

24681012495051525354 Day Price

━ Close   ━ Middle band (5-day mean)   ┄ Upper and lower bands (mean ± 2 SD)

The bands from the worked example below hug the price while it climbs gently, then flare open on days 11 and 12 when two sharp falls inflate the rolling SD.

A rolling standard deviation

An ordinary standard deviation is one number for a whole dataset. A rolling (or moving) standard deviation is a series of them: take the last k values, compute their SD, move forward one step, drop the oldest value, add the newest, and compute again. The window slides along the data, and each point on the chart describes only the spread inside its own window.

The usual Bollinger settings are a 20-period window and a width of 2:

middle band = mean of the last 20 closes upper band = middle + 2 × SD of the last 20 closes lower band = middle − 2 × SD of the last 20 closes

The SD in the standard definition divides by the window length n, which makes it the population standard deviation of the window. The window is treated as the whole population of interest, not as a sample of something larger. Some software uses n − 1 instead, which makes the bands a little wider.

A worked example

Twenty closes make a long table, so this example uses a 5-period window. The mechanics are identical; only k changes. The twelve closing prices are invented for illustration:

50.0, 50.6, 51.2, 50.8, 51.5, 52.3, 52.0, 52.8, 53.4, 51.9, 50.2, 49.6

The first full window is the first five closes: 50.0, 50.6, 51.2, 50.8, 51.5. Their mean is 254.1 ÷ 5 = 50.82. The deviations from that mean are −0.82, −0.22, 0.38, −0.02 and 0.68. Squared, they sum to 1.328, so the population variance is 1.328 ÷ 5 = 0.2656 and the SD is √0.2656 = 0.515. The bands are 50.82 ± 2 × 0.515, from 49.79 to 51.85. Then the window moves on by one close and the whole calculation repeats.

DayClose5-day mean5-day SDLower bandUpper bandBandwidth
551.550.820.51549.7951.854.06%
652.351.280.59850.0852.484.66%
752.051.560.53950.4852.644.18%
852.851.880.68550.5153.255.28%
953.452.400.65451.0953.714.99%
1051.952.480.55651.3753.594.24%
1150.252.061.08049.9054.228.30%
1249.651.581.46548.6554.5111.36%

Bandwidth is the distance between the bands as a share of the middle band, (upper − lower) ÷ middle, which works out to 4 × SD ÷ mean. It is a coefficient of variation multiplied by four, and it makes band width comparable across a $5 stock and a $500 one.

Read the table from top to bottom. On days 5 to 10 the price climbs gently and the SD stays between about 0.5 and 0.7, so the bands are narrow. On day 11 the close drops 1.7 below the previous day's, and the SD nearly doubles to 1.08. Day 12 falls again and the SD reaches 1.465. The bandwidth has almost tripled in two days, from 4.24% to 11.36%.

Notice also that the close on day 11 (50.2) is just above the lower band (49.90), even though it is the sharpest fall in the series. That is a built-in feature of the method: the new close is part of the window, so a big move inflates the very SD it is being measured against. A price can only get so far outside bands that are computed from itself.

Try it: population standard deviation calculator

The first 5-day window (days 1 to 5) is filled in below and gives the 0.515 from the table; paste in any later window, or your own closes, to get that window's SD and mean.

Separate numbers with commas, spaces or new lines, or paste a spreadsheet column. Decimals and negatives are fine; write 10:3 for a value that occurs 3 times.

Try:
Calculation type

Not sure which? How to choose sample or population

Standard deviation (population)

0.515364

Your values typically sit about 0.515 above or below their mean of 50.82, in the same units as your data. 3 of 5 values (60%) fall between 50.3 and 51.34, within one standard deviation of the mean; for normally distributed data about 68% would.

Sample SD (s): 0.576194, if these values are a sample from a larger group.

Count (n)
5
Mean (x̄)
50.82
Variance (σ²)
0.2656
Standard error
0.230478
Minimum
50
Q1 (25%)
50.6
Median
50.8
Q3 (75%)
51.2
Maximum
51.5
Range
1.5
More statistics (5)
Relative SD (%RSD)
1.0141%
Coefficient of variation
0.010141
Sum (Σx)
254.1
Sum of squares, Σ(x − x̄)²
1.328
IQR (Q3 − Q1)
0.6

Data distribution

49.5 50 50.5 51 51.5 52 mean 50.82 −1 SD +1 SD 50 — 1.59 SD below the mean50.6 — 0.427 SD below the mean51.2 — 0.737 SD above the mean50.8 — 0.0388 SD below the mean51.5 — 1.32 SD above the mean Value

Shaded bands mark ±1, ±2 and ±3 SD from the mean. 3 of 5 values (60%) fall within ±1 SD.

Chart as text

Mean 50.82, population standard deviation σ = 0.515364, from 5 values between 50 and 51.5.

  • Within ±1 SD (50.3 to 51.34): 3 of 5 values (60%). About 68% for normal data.
  • Within ±2 SD: 5 (100%). About 95% for normal data.
  • Within ±3 SD: 5 (100%). About 99.7% for normal data.
Show the working, step by step

Open the full population standard deviation calculator for the divide-by-n formula worked step by step.

What a squeeze means

A squeeze is a stretch where bandwidth drops to a low level compared with its own recent history. It means the rolling SD is small: the last 20 closes are tightly bunched. That is a description of the recent past, not a prediction, but traders watch for it because periods of low volatility in markets tend to be followed by periods of higher volatility. The squeeze tells you the spread is unusually small. It does not tell you which way the next move will go. Days 5 to 10 in the table are a small version of a squeeze, and day 11 shows the bands flaring open when it ends.

Why ±2 SD does not mean 95%

For a normal distribution, 95.45% of values fall within 2 standard deviations of the mean. It is tempting to read Bollinger Bands the same way and expect 95% of closes inside them. There are four reasons not to.

The 95% rule assumesWhat happens with prices
A fixed mean and SDBoth are re-estimated every period from 20 points, so they carry sampling error and lag behind the price.
Independent observationsConsecutive closes are strongly related; today's price is yesterday's price plus a change.
A bell-shaped distributionPrice changes have fatter tails than a normal curve, so large moves are more common.
The value is not part of the estimateThe current close is inside its own window, which pulls the bands toward it.

The second point is the most important. The SD is a spread measure for values scattered around a stable centre, and prices do not scatter around their 20-day average; they wander, and the average follows them. The fraction of closes inside the bands depends on the asset, the period and whether the market is trending, so it has to be measured, not assumed. If you want a probability statement, work with returns rather than price levels, and check the empirical rule against your own data before relying on it.

Using a rolling SD outside trading

Nothing about the technique is specific to prices. A rolling SD over the last 30 readings is a quick way to see whether a sensor, a website's daily sign-ups or a production line has become more erratic. The same caveats apply: the window length sets the trade-off between speed and noise, and a band drawn from recent data describes recent data, nothing more.

Common questions

Do Bollinger Bands use the sample or population standard deviation?

The standard definition divides by n, the population formula, over the window. Some charting tools use n − 1 instead. With a 20-period window the sample SD is about 2.6% larger (√(20/19) = 1.026), so the bands are slightly wider. It matters only when you compare figures between tools.

Why 20 periods and 2 standard deviations?

They are conventions, not results. Twenty periods is roughly a month of trading days, and 2 SD puts the bands far enough out that most closes fall inside them. Both can be changed; a shorter window reacts faster and gives noisier bands, a longer one is smoother and slower.

Does a close outside the upper band mean the price will fall?

No. A close above the upper band says the latest price is unusually high relative to the last 20 closes. In a strong trend prices can ride along the band for many periods. The bands describe recent spread; they do not forecast direction.