Average true range (ATR) is a lagging volatility indicator. ATR is a measure of volatility. High ATR values indicate high volatility, and low values indicate low volatility.
The formula for computing ATR is not straightforward and is hence not mentioned here. If you are interested in the underlying math, please refer to the official documentation of TA-Lib on ATR at http://www.tadoc.org/indicator/ATR.htm. Although it is a good idea to know the mathematics of how this works, this recipe does not require you to understand or remember the given formula. We use a third-party Python package, talib, which provides a ready function for calculating ATR.
Getting started
Make sure your Python namespace has the following objects:
- talib (package)
- pd (module)
- plot_candlesticks_chart (function)
- PlotType (enum)
- historical_data (a pandas DataFrame)
Refer to the Technical requirements section of this chapter to set up these objects.