Average True Range (ATR)
I. What is ATR
The Average True Range (ATR) is a volatility indicator first introduced by American technical analysis pioneer J. Welles Wilder Jr. in 1978 in his classic book New Concepts in Technical Trading Systems.
ATR belongs to the Volatility class of indicators. It measures the magnitude of price fluctuations over a given period without indicating direction. The default period is .
Unlike simply using High - Low to measure volatility, ATR introduces the concept of “True Range” (TR), which incorporates the previous bar’s closing price into the calculation, thereby accurately capturing the additional volatility caused by price gaps.
ATR is a core component of many other technical indicators, including SuperTrend, Keltner Channels, ADX, and various volatility-based stop-loss methods.
ATR only measures the magnitude of volatility and provides no directional information. A rising ATR indicates increasing volatility (which could be either upward or downward), while a falling ATR indicates contracting volatility.
II. Mathematical Principles and Calculation
2.1 True Range (TR)
For the -th bar, the True Range is defined as the maximum of the following three values:
Where:
- = current high price
- = current low price
- = previous bar’s closing price
The three components represent:
- : the current bar’s range
- : the distance between the current high and the previous close (captures upward gaps)
- : the distance between the current low and the previous close (captures downward gaps)
2.2 ATR Calculation
ATR uses Wilder’s Smoothing Method (SMMA) to smooth the TR series:
First ATR value (at the -th bar):
This is the simple moving average of the first TR values.
Subsequent ATR values ():
When :
Wilder’s Smoothing is essentially equivalent to an Exponential Moving Average (EMA) with smoothing factor . Compared to a standard EMA (), Wilder’s Smoothing assigns higher weight to historical data, resulting in a smoother output.
2.3 Calculation Steps Summary
- Calculate the True Range for each bar
- Take the simple average of the first 14 TR values as the initial ATR
- Apply the recursive formula: ATR = (previous ATR x 13 + current TR) / 14
- Repeat step 3 until the end of the series
III. Python Implementation
import numpy as np
import pandas as pd
def atr(high: pd.Series, low: pd.Series, close: pd.Series,
period: int = 14) -> pd.Series:
"""
Calculate the Average True Range (ATR).
Parameters:
high : Series of high prices
low : Series of low prices
close : Series of closing prices
period : Smoothing period, default 14
Returns:
ATR series (Wilder's Smoothing)
"""
# Calculate True Range
prev_close = close.shift(1)
tr1 = high - low
tr2 = (high - prev_close).abs()
tr3 = (low - prev_close).abs()
tr = pd.concat([tr1, tr2, tr3], axis=1).max(axis=1)
# Apply Wilder's Smoothing (equivalent to EMA with alpha=1/period)
atr_values = pd.Series(np.nan, index=close.index)
# First ATR = SMA of the first 'period' TR values
first_atr = tr.iloc[1:period + 1].mean() # TR is valid from the 2nd bar
atr_values.iloc[period] = first_atr
# Recursively calculate subsequent ATR values
for i in range(period + 1, len(close)):
atr_values.iloc[i] = (atr_values.iloc[i - 1] * (period - 1) + tr.iloc[i]) / period
return atr_values
# ============ Usage Example ============
if __name__ == '__main__':
np.random.seed(42)
n_days = 100
# Generate simulated OHLCV data
base_price = 100 + np.cumsum(np.random.randn(n_days) * 0.5)
df = pd.DataFrame({
'open': base_price + np.random.randn(n_days) * 0.3,
'high': base_price + np.abs(np.random.randn(n_days) * 0.8),
'low': base_price - np.abs(np.random.randn(n_days) * 0.8),
'close': base_price,
'volume': np.random.randint(1000, 10000, n_days)
})
# Calculate ATR
df['ATR'] = atr(df['high'], df['low'], df['close'], period=14)
print("=== ATR Results (Last 10 Rows) ===")
print(df[['close', 'high', 'low', 'ATR']].tail(10).to_string())
# ATR-based stop-loss example
df['stop_loss_long'] = df['close'] - 2.0 * df['ATR'] # Long stop-loss
df['stop_loss_short'] = df['close'] + 2.0 * df['ATR'] # Short stop-loss
print("\n=== ATR Stop-Loss Levels (Last 5 Rows) ===")
print(df[['close', 'ATR', 'stop_loss_long', 'stop_loss_short']].tail(5).to_string())
IV. Problems the Indicator Solves
4.1 Volatility Measurement
ATR is the most direct and pure volatility measurement tool. It unifies “bar body + gaps” into a single consideration, accurately reflecting how far market participants are willing to push the price within a given time frame.
- Rising ATR: market volatility is increasing, uncertainty is growing
- Falling ATR: the market is calming down, possibly in a consolidation phase
4.2 Stop-Loss Placement
ATR is widely used for adaptive stop-loss calculation. A common approach is to set the stop-loss at the entry price +/- .
| Multiplier | Characteristics |
|---|---|
| 1.0 | Tight stop, easily triggered, suitable for short-term trading |
| 1.5 | Moderate stop, balances protection and tolerance |
| 2.0 | Loose stop, gives price sufficient breathing room |
| 3.0 | Very loose, suitable for long-term trend following |
ATR-based stops are adaptive — the stop distance automatically widens during high-volatility periods and tightens during low-volatility periods. Traders should be aware of the impact on position sizing: during high volatility, each unit carries a larger dollar risk.
4.3 Position Sizing
ATR can be used to normalize volatility across different instruments, enabling equal-risk position allocation:
This is the core position sizing philosophy of the Turtle Trading rules.
4.4 Volatility Breakout Strategy
When the price breaks above or below , it is considered a move beyond the normal volatility range and may signal the start of a new trend.
4.5 Applications in Other Indicators
ATR is a core component of the following indicators:
- SuperTrend: a dynamic trend-following stop-loss line built on ATR
- Keltner Channels: channels constructed using ATR instead of standard deviation
- ADX: uses ATR to normalize directional movement
- Chandelier Exit: ATR-based trailing stop-loss
V. Advantages, Disadvantages, and Use Cases
Advantages
| Advantage | Description |
|---|---|
| Accurately captures gaps | True Range incorporates gaps into volatility, more accurate than High - Low |
| Adaptive | Automatically adjusts with market conditions, no manual parameter changes needed |
| Wide range of applications | Stop-loss, position sizing, volatility filtering, building block for other indicators |
| Cross-instrument comparability | Standardized volatility measurement for horizontal comparison across markets |
| Simple and stable calculation | Wilder’s recursive smoothing is computationally efficient and numerically stable |
Disadvantages
| Disadvantage | Description |
|---|---|
| No directional information | ATR cannot determine trend direction; must be combined with directional indicators |
| Lagging | As a moving average of historical data, it reacts with a delay to sudden volatility changes |
| Absolute value affected by price level | High-priced assets have larger absolute ATR; use ATR% for cross-instrument comparison |
| Does not distinguish up vs. down volatility | Both sharp rallies and sharp declines cause ATR to rise |
Use Cases
- Best suited for: stop-loss placement, position sizing, volatility filters
- Well suited for: combining with trend indicators to gauge trend “energy”
- Not suited for: use as a standalone buy/sell signal generator
Comparison with Similar Indicators
| Indicator | Volatility Measurement Method | Characteristics |
|---|---|---|
| ATR | Wilder’s smoothing of True Range | Accounts for gaps, smooth and stable |
| Standard Deviation (sigma) | Degree of closing price deviation from the mean | Sensitive to extreme values |
| Historical Volatility | Standard deviation of log returns | Annualized and comparable, suitable for options pricing |
| Parkinson Volatility | Uses only High/Low | More efficient than close-based methods, but ignores gaps |
Parameter Tuning Recommendations: A 14-period setting works well for most scenarios. Short-term traders may use 7 or 10 periods for faster responsiveness; long-term traders may use 20 or 21 periods for a smoother volatility curve. For cross-instrument comparison, consider using ATR Percentage: .