Skip to main content

Quant Analytics: from scratch to pro · Indicators, honestly measured · Intermediate

ATR, Bollinger Bands and volatility envelopes

The Average True Range and Bollinger Bands are two ways to draw a price's recent variability on a chart. Both are measures of past spread, useful as a ruler for distances and position size, and neither tells you where the price goes next.

4 min read Reviewed Revision 1

In this lesson

  • Compute the true range for a bar, including a gap, and update an ATR
  • Build Bollinger Bands from a moving average and a standard deviation
  • Use ATR as a ruler to convert a risk amount into a position size
  • Explain what the bands do and do not say about probability

Read first: Moving averages and their lag, Volatility explained

Worked numbers

Each result is recomputed from the formula shown.

WhatFormulaResult
true range of the bar with a gapmax(104 - 101, abs(104 - 100), abs(101 - 100))4
ATR(14) after a true range of 4(2.5 * 13 + tr_gap) / 142.607
stop distance of 2.5 ATR2.5 * atr_new6.52
risk of 1% on 50,0000.01 * 50000500
position size, unroundedrisk_amt / stop_dist76.7
mean of five closes(98 + 100 + 101 + 103 + 98) / 5100
population variance of the five closes((98 - mean5)**2 + (100 - mean5)**2 + (101 - mean5)**2 + (103 - mean5)**2 + (98 - mean5)**2) / 53.6
population standard deviationsqrt(var5)1.90
upper band, 2 standard deviationsmean5 + 2 * sd5103.79
lower bandmean5 - 2 * sd596.21
bandwidth of the 20-period example(105 - 95) / 10010%
percent b for a price of 103(103 - 95) / (105 - 95)0.80
normal share inside two standard deviations2 * phi(2) - 195.45%

Check yourself

Yesterday's close was 100. Today the bar has a high of 104 and a low of 101. What is the true range?

The largest of high - low = 3, |high - previous close| = 4 and |low - previous close| = 1. So 4. The high-low range alone misses the gap.

The ATR(14) is 2.5 and today's true range is 4. What is the new ATR?

(2.5 x 13 + 4) / 14 = 2.607.

A 20-period average is 100 and the standard deviation of the closes is 2.5. Where are the bands, and what is the bandwidth?

Upper 105, lower 95. Bandwidth = (105 - 95) / 100 = 10%.

A price of 103 sits inside those bands. What is %b?

(103 - 95) / (105 - 95) = 0.80, which is four-fifths of the way from the lower to the upper band.

If returns were normal, what share of closes would fall inside a two-standard-deviation band?

About 95.45%. Real returns have fatter tails, and the bands move with the data, so the real share is not a fixed number.

Key terms

Average True RangeBollinger BandsStandard deviationGap

Sources

  • New Concepts in Technical Trading Systems. Trend Research (J. Welles Wilder Jr.), 1978. Accessed 9 Nov 2026
  • Bollinger on Bollinger Bands. McGraw-Hill (John Bollinger), 2001. Accessed 9 Nov 2026
  • The Econometrics of Financial Markets. Princeton University Press (John Y. Campbell, Andrew W. Lo, A. Craig MacKinlay), 1997. Accessed 9 Nov 2026

Informational content. Not investment advice.