Skip to content

trading.indicators.calculations.average_true_range

trading.indicators.calculations.average_true_range

AverageTrueRange

AverageTrueRange(period: days = 14)

Bases: Indicator[float | None]

The average true range (volatility measure).

Initializes AverageTrueRange.

Parameters:

Name Type Description Default
period days

Lookback period used to smooth the True Range.

14
Source code in src\contango\trading\indicators\calculations\average_true_range.py
32
33
34
35
36
37
38
39
40
def __init__(self, period: days = 14) -> None:
    """
    Initializes `AverageTrueRange`.

    Args:
        period: Lookback period used to smooth the True Range.
    """
    self._true_range = TrueRange()
    self._average = WilderAverage(period)

update

update(high: USD, low: USD, close: USD) -> float | None

Updates the ATR for each bar.

Parameters:

Name Type Description Default
high USD

The highest price reached in USD for a bar.

required
low USD

The lowest price reached in USD for a bar.

required
close USD

The closing price in USD for a bar.

required

Returns:

Type Description
float | None

The current ATR. Returns None until enough bars have been

float | None

observed to initialize the Wilder average.

Source code in src\contango\trading\indicators\calculations\average_true_range.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def update(self, high: USD, low: USD, close: USD) -> float | None:
    """
    Updates the ATR for each bar.

    Args:
        high: The highest price reached in USD for a bar.
        low: The lowest price reached in USD for a bar.
        close: The closing price in USD for a bar.

    Returns:
        The current ATR. Returns None until enough bars have been
        observed to initialize the Wilder average.
    """
    tr = self._true_range.update(high, low, close)
    return self._average.update(tr)