MyAlgoMate
// INDICATOR FORMULA

Bollinger Bands formula: how to calculate them (with Excel)

How the three Bollinger Bands are worked out — a 20-period average with bands two standard deviations above and below it — plus %B and bandwidth. With a worked example, the Excel formulas, a free Excel sheet and a box to calculate the bands from your own prices.

Last updated:

Download the free Bollinger Bands Excel sheet (.xlsx)

Needs: closing prices · Standard settings: Period 20 · Std dev multiplier 2

The Bollinger Bands formula

Middle band = SMA (20) of the close
Std dev     = √( Σ (Close − Middle band)² ÷ 20 )     over the same 20 closes
Upper band  = Middle band + 2 × Std dev
Lower band  = Middle band − 2 × Std dev

%B          = (Close − Lower band) ÷ (Upper band − Lower band)
Bandwidth % = (Upper band − Lower band) ÷ Middle band × 100

The standard deviation divides by 20 (the “population” version, Excel's STDEVP), not 19. 20 and 2 are the usual settings; change them in the calculator below.

How to calculate Bollinger Bands step by step

  1. Average the last 20 closes for the middle band. The first full set is Day 1 to Day 20: middle band 1,018.39.
  2. Work out the standard deviation of the same 20 closes. Subtract the middle band from each close, square the differences, average them and take the square root: 32.60.
  3. Add and subtract twice the standard deviation. Upper band = 1,018.39 + 2 × 32.60 = 1,083.59; lower band = 1,018.39 − 2 × 32.60 = 953.20.
  4. Optional: %B and bandwidth. Day 20 closed at 960.90: %B = (960.90 − 953.20) ÷ (1,083.59 − 953.20) = 0.0591. Bandwidth = (1,083.59 − 953.20) ÷ 1,018.39 × 100 = 12.80%.
  5. Move the 20-candle window on and repeat. On Day 60 the example's bands are 1,018.42 / 953.00 / 887.58.

Worked example — and calculate Bollinger Bands from your own prices

The table works through 60 daily candles of an imaginary stock, column by column — the same columns as the Excel sheet. To calculate Bollinger Bands for your own stock, clear the box and paste your closing prices from Excel or your broker's download.

One row per candle, oldest first. Paste straight from Excel or your broker's download; a date or time column becomes the row label. Filled with our example prices.

Latest values

Upper band: 1,018.4177Middle (SMA 20): 952.9975Lower band: 887.5773
Bollinger Bands calculated from the example prices
DayCloseMiddle (SMA 20)Std devUpper bandLower band%BBandwidth %
Day 11,001.15
Day 2987.95
Day 31,009.15
Day 41,012.60
Day 5993.25
Day 61,008.60
Day 71,013.60
Day 81,001.55
Day 91,031.55
Day 101,040.05
Day 111,033.15
Day 121,064.80
Day 131,083.55
Day 141,067.95
Day 151,063.50
Day 161,030.20
Day 171,012.20
Day 18981.60
Day 19970.55
Day 20960.901,018.392532.59851,083.5894953.19560.059112.8039
Day 21978.301,017.250033.56871,084.3874950.11260.209913.1998
Day 22958.851,015.795035.38851,086.5720945.01800.097713.9353
Day 23946.751,012.675038.45471,089.5844935.76560.071415.1894
Day 24937.951,008.942541.76151,092.4655925.41950.075016.5565
Day 25927.851,005.672545.27491,096.2223915.12270.070318.0078
Day 26911.201,000.802549.71851,100.2394901.36560.049519.8714
Day 27905.15995.380053.77551,102.9310887.82900.080521.6100
Day 28885.95989.600058.78131,107.1625872.03750.059223.7596
Day 29874.70981.757562.97491,107.7074855.80760.075025.6580
Day 30855.80972.545067.11441,106.7737838.31630.065127.6036
Day 31862.15963.995069.69171,103.3785824.61150.134728.9179
Day 32866.45954.077568.74771,091.5730816.58200.181328.8227
Day 33845.10942.155065.87681,073.9086810.40140.131727.9686
Day 34851.55931.335061.98331,055.3015807.36850.178226.6213
Day 35860.20921.170055.84111,032.8522809.48780.227024.2479
Day 36854.80912.400051.64481,015.6896809.11040.221222.6413
Day 37877.20905.650046.7501999.1502812.14980.347920.6482
Day 38888.45900.992543.4770987.9466814.03840.427919.3018
Day 39905.40897.735040.4809978.6967816.77330.547318.0369
Day 40896.80894.530037.8019970.1338818.92620.515016.9036
Day 41889.60890.095032.5524955.1998824.99020.496214.6287
Day 42895.30886.917528.5404943.9982829.83680.573412.8717
Day 43919.00885.530026.1743937.8787833.18130.819711.8231
Day 44918.35884.550024.5071933.5643835.53570.844811.0823
Day 45906.25883.470023.0051929.4802837.45980.747610.4158
Day 46932.10884.515024.6564933.8278835.20220.982511.1502
Day 47944.35886.475027.6010941.6771831.27291.024212.4543
Day 48948.70889.612530.7499951.1123828.11270.980413.8262
Day 49966.35894.195034.7544963.7039824.68611.019015.5467
Day 50955.60899.185036.0249971.2347827.13530.891516.0256
Day 51969.10904.532538.0134980.5594828.50560.924616.8102
Day 52984.35910.427540.6976991.8228829.03220.954117.8807
Day 53980.90917.217540.5602998.3379836.09710.892517.6884
Day 54962.50922.765038.74621,000.2574845.27260.756416.7957
Day 55960.20927.765036.75071,001.2665854.26350.720615.8449
Day 56967.35933.392533.63191,000.6562866.12880.752414.4127
Day 57971.00938.082531.96781,002.0182874.14680.757413.6311
Day 58981.75942.747531.18261,005.1127880.38230.812713.2305
Day 59994.85947.220031.91151,011.0430883.39700.873113.4758
Day 601,012.35952.997532.71011,018.4177887.57730.953613.7294
Everything is worked out in your browser. Nothing you paste is stored or sent.

The example prices are made up for this page — they are not real market data. Bollinger Bands is a calculation from past prices, not a forecast, a signal or advice to buy or sell. MyAlgoMate provides trading technology, not investment advice.

How to calculate Bollinger Bands in Excel

Put the headings in row 1 and the first candle in row 2, oldest at the top. Then type these formulas — each column uses the ones to its left:

  1. A

    Day

    A2 downwards: your dates, oldest at the top.

  2. B

    Close

    B2 downwards: the closing prices, oldest at the top.

  3. C

    Middle (SMA 20)

    C21 =AVERAGE(B2:B21) — then copy it down to the last row.

  4. D

    Std dev

    D21 =STDEVP(B2:B21) — then copy it down to the last row.

  5. E

    Upper band

    E21 =C21+2*D21 — then copy it down to the last row.

  6. F

    Lower band

    F21 =C21-2*D21 — then copy it down to the last row.

  7. G

    %B

    G21 =(B21-F21)/(E21-F21) — then copy it down to the last row.

  8. H

    Bandwidth %

    H21 =(E21-F21)/C21*100 — then copy it down to the last row.

The first 19 rows stay empty: every value needs 20 closes.

Prefer not to type them? The free sheet has every formula filled in for the example prices — replace the prices with yours and extend the rows. It opens in Microsoft Excel (we checked every value against the table above), and you can import it into Google Sheets or LibreOffice.

Download the free Bollinger Bands Excel sheet (.xlsx)

What are Bollinger Bands?

Bollinger Bands are three lines on a price chart: a moving average in the middle and a band a set number of standard deviations above and below it. John Bollinger created them in the early 1980s, and his official site (bollingerbands.com) describes the idea as asking whether prices are high or low on a relative basis. People also search for them as “band Bollinger” — it is the same indicator.

The bands are a calculation from past prices. They are not a forecast, and this page does not suggest any trade.

Common settings

Common Bollinger Bands settings
UseAverage periodStandard deviations
Shorter term101.5
Default, medium term202
Longer term502.5

The table follows Fidelity's guide to typical values. John Bollinger's own note is to scale the multiplier with the length of the average: about 2.1 at 50 periods and 1.9 at 10 periods.

What John Bollinger says about the bands

His Bollinger Band rules include these points about reading the maths:

  • Touches of the bands are “tags, not signals”.
  • A close outside the bands is initially a sign of continuation, not a reversal.
  • The default settings are starting points; the right values vary by market and task.
  • About 90% of prices fall inside the default bands, not the 95% of a normal curve.
  • Bandwidth's most popular use is spotting “the squeeze”.

Simple or exponential bands

Classic Bollinger Bands use a simple moving average, so the average and the standard deviation cover the same closes. If you use an exponential average instead, change it for both the middle band and the standard deviation.

At the defaults, bandwidth = (upper − lower) ÷ middle = 4 × standard deviation ÷ middle. The table below checks this on the worked example.

Bandwidth check on the worked example
DayStd devMiddle band(Upper − lower) ÷ middle4 × std dev ÷ middle
Day 2032.59851,018.39250.12800.1280
Day 3067.1144972.54500.27600.2760
Day 4037.8019894.53000.16900.1690
Day 5036.0249899.18500.16030.1603
Day 6032.7101952.99750.13730.1373

How many example closes fall inside the bands?

On the worked example's made-up prices, Day 20 to Day 60 (41 closes that have bands), a count from the table above:

Closes inside, above and below the bands in the worked example
Where the close isNumber of closes
Inside the bands39
Above the upper band2
Below the lower band0

These prices are invented to show the calculation, so the counts say nothing about real markets. Paste your own closes into the calculator above to count yours.

What the bands show

The bands widen when the last 20 closes are spread out and narrow when they are bunched together, so the distance between them is a measure of recent volatility. A very narrow bandwidth is often called a “squeeze” — a description of quiet recent prices, not a forecast of what comes next.

A close outside the bands only means it is more than two standard deviations from the 20-period average. What you do with any of this is your own decision; the bands are a calculation from past prices.

Why your bands may not match your chart

  • Sample instead of population standard deviation (STDEV / STDEV.S) — slightly wider bands.
  • Different settings — period, multiplier, or an EMA instead of an SMA for the middle band.
  • Different prices — spot vs futures, or another timeframe.

The middle band is an ordinary simple moving average — see the moving average formula.

// FAQ

Bollinger Bands calculation — questions, answered.

Yes. "Band Bollinger" is a common way of searching for Bollinger Bands, the indicator John Bollinger created in the early 1980s: a moving average with a band a set number of standard deviations above and below it.

John Bollinger's website says about 90% of prices fall inside the default bands, not the 95% a normal bell curve would give, because prices are not normally distributed. Studies cited on Wikipedia found about 88%. This describes how the maths behaves, nothing more.

They are the standard defaults: a 20-period average and 2 standard deviations. John Bollinger calls the defaults a starting point, and suggests a slightly larger multiplier for a longer average (2.1 at 50 periods) and a smaller one for a shorter average (1.9 at 10 periods).

The middle band is the 20-period simple moving average of the close. Work out the standard deviation of the same 20 closes; the upper band is the middle band + 2 × that standard deviation and the lower band is the middle band − 2 × it.

Closes in column B from row 2. In row 21 (the 20th close): middle =AVERAGE(B2:B21), standard deviation =STDEVP(B2:B21) (or STDEV.P), upper =C21+2*D21, lower =C21-2*D21. Copy the row down. The free sheet on this page also has %B and bandwidth.

The population standard deviation — dividing by 20, not 19 — which is STDEVP or STDEV.P in Excel. That is how John Bollinger defined it and how most charts calculate it. STDEV / STDEV.S divide by 19 and give slightly wider bands, a common reason a spreadsheet doesn't match a chart.

%B = (Close − Lower band) ÷ (Upper band − Lower band). It says where the close sits between the bands: 0 at the lower band, 1 at the upper band, 0.5 at the middle. It goes above 1 or below 0 when the close is outside the bands.

Bandwidth = (Upper band − Lower band) ÷ Middle band, often × 100 to show it as a percentage. Because the bands are 2 standard deviations either side, it equals 4 × standard deviation ÷ middle band — a measure of how spread out the last 20 closes are.

Bollinger Bands are set by the standard deviation of the closes around a simple moving average. Keltner Channels are usually set by a multiple of the Average True Range around an exponential moving average. See the ATR formula page for how ATR is calculated.

More indicator formulas, with Excel sheets

Turn your own rules into automated orders.

Already use Bollinger Bands in your own rules? MyAlgoMate's algo trading software places the orders your rules call for at 150+ Indian brokers — and TradeBridge turns your own TradingView or Chartink alerts into live orders. You decide the rules; we provide the technology.

Share this page