Average True Range (ATR)

Haiyue
10min

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 n=14n = 14.

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.

Tip

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 tt-th bar, the True Range is defined as the maximum of the following three values:

TRt=max(HtLt,  HtCt1,  LtCt1)\text{TR}_t = \max\bigl(H_t - L_t,\; |H_t - C_{t-1}|,\; |L_t - C_{t-1}|\bigr)

Where:

  • HtH_t = current high price
  • LtL_t = current low price
  • Ct1C_{t-1} = previous bar’s closing price

The three components represent:

  1. HtLtH_t - L_t: the current bar’s range
  2. HtCt1|H_t - C_{t-1}|: the distance between the current high and the previous close (captures upward gaps)
  3. LtCt1|L_t - C_{t-1}|: 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 nn-th bar):

ATRn=1ni=1nTRi\text{ATR}_n = \frac{1}{n} \sum_{i=1}^{n} \text{TR}_i

This is the simple moving average of the first nn TR values.

Subsequent ATR values (t>nt > n):

ATRt=ATRt1×(n1)+TRtn\text{ATR}_t = \frac{\text{ATR}_{t-1} \times (n - 1) + \text{TR}_t}{n}

When n=14n = 14:

ATRt=ATRt1×13+TRt14\text{ATR}_t = \frac{\text{ATR}_{t-1} \times 13 + \text{TR}_t}{14}
Note

Wilder’s Smoothing is essentially equivalent to an Exponential Moving Average (EMA) with smoothing factor α=1/n\alpha = 1/n. Compared to a standard EMA (α=2/(n+1)\alpha = 2/(n+1)), Wilder’s Smoothing assigns higher weight to historical data, resulting in a smoother output.

2.3 Calculation Steps Summary

  1. Calculate the True Range for each bar
  2. Take the simple average of the first 14 TR values as the initial ATR
  3. Apply the recursive formula: ATR = (previous ATR x 13 + current TR) / 14
  4. 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 +/- k×ATRk \times \text{ATR}.

Multiplier kkCharacteristics
1.0Tight stop, easily triggered, suitable for short-term trading
1.5Moderate stop, balances protection and tolerance
2.0Loose stop, gives price sufficient breathing room
3.0Very loose, suitable for long-term trend following
Warning

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:

Position Size=Risk Per Tradek×ATR×Contract Multiplier\text{Position Size} = \frac{\text{Risk Per Trade}}{k \times \text{ATR} \times \text{Contract Multiplier}}

This is the core position sizing philosophy of the Turtle Trading rules.

4.4 Volatility Breakout Strategy

When the price breaks above or below Closet1±k×ATR\text{Close}_{t-1} \pm k \times \text{ATR}, 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

AdvantageDescription
Accurately captures gapsTrue Range incorporates gaps into volatility, more accurate than High - Low
AdaptiveAutomatically adjusts with market conditions, no manual parameter changes needed
Wide range of applicationsStop-loss, position sizing, volatility filtering, building block for other indicators
Cross-instrument comparabilityStandardized volatility measurement for horizontal comparison across markets
Simple and stable calculationWilder’s recursive smoothing is computationally efficient and numerically stable

Disadvantages

DisadvantageDescription
No directional informationATR cannot determine trend direction; must be combined with directional indicators
LaggingAs a moving average of historical data, it reacts with a delay to sudden volatility changes
Absolute value affected by price levelHigh-priced assets have larger absolute ATR; use ATR% for cross-instrument comparison
Does not distinguish up vs. down volatilityBoth 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

IndicatorVolatility Measurement MethodCharacteristics
ATRWilder’s smoothing of True RangeAccounts for gaps, smooth and stable
Standard Deviation (sigma)Degree of closing price deviation from the meanSensitive to extreme values
Historical VolatilityStandard deviation of log returnsAnnualized and comparable, suitable for options pricing
Parkinson VolatilityUses only High/LowMore efficient than close-based methods, but ignores gaps
Tip

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: ATR%=ATR/Close×100\text{ATR\%} = \text{ATR} / \text{Close} \times 100.