backtrader.indicators.atr module

ATR Indicator Module - Average True Range.

This module provides the ATR (Average True Range) indicator developed by J. Welles Wilder, Jr. for measuring market volatility.

Classes:

TrueHigh: Records the true high for ATR calculation. TrueLow: Records the true low for ATR calculation. TrueRange: Calculates the True Range. AverageTrueRange: Calculates the Average True Range (alias: ATR).

Example

class MyStrategy(bt.Strategy):
def __init__(self):

self.atr = bt.indicators.ATR(self.data, period=14)

def next(self):
if self.atr[0] > self.atr[-1] * 1.5:

self.buy()

class backtrader.indicators.atr.TrueHigh[source]

Bases: Indicator

Defined by J. Welles Wilder, Jr. in 1978 in his book “New Concepts in Technical Trading Systems” for the ATR

Records the “true high” which is the maximum of today’s high and yesterday’s close

Formula:
  • truehigh = max (high, close_prev)

See:
__init__(*args, **kwargs)
next()[source]

Calculate true high: max(high, previous_close).

once(start, end)[source]

Calculate true high in runonce mode.

frompackages = ()
packages = ()
class backtrader.indicators.atr.TrueLow[source]

Bases: Indicator

Defined by J. Welles Wilder, Jr. in 1978 in his book “New Concepts in Technical Trading Systems” for the ATR

Records the “true low” which is the minimum of today’s low and yesterday’s close

Formula:
  • truelow = min (low, close_prev)

See:
__init__(*args, **kwargs)
next()[source]

Calculate true low: min(low, previous_close).

once(start, end)[source]

Calculate true low in runonce mode.

frompackages = ()
packages = ()
class backtrader.indicators.atr.TrueRange[source]

Bases: Indicator

Defined by J. Welles Wilder, Jr. in 1978 in his book New Concepts in Technical Trading Systems.

Formula:
  • max(high - low, abs (high - prev_close), abs(prev_close - low)

Which can be simplified to

  • Max(high, prev_close) - min(low, prev_close)

See:

The idea is to take the previous close into account to calculate the range if it yields a larger range than the daily range (High - Low)

alias = ('TR',)
__init__(*args, **kwargs)
next()[source]

Calculate true range: truehigh - truelow.

once(start, end)[source]

Calculate true range in runonce mode.

frompackages = ()
packages = ()
class backtrader.indicators.atr.AverageTrueRange[source]

Bases: Indicator

Defined by J. Welles Wilder, Jr. in 1978 in his book “New Concepts in Technical Trading Systems”.

The idea is to take the close into account to calculate the range if it yields a larger range than the daily range (High - Low)

Formula:
  • SmoothedMovingAverage(TrueRange, period)

See:
alias = ('ATR',)
__init__(*args, **kwargs)
nextstart()[source]

Seed ATR with SMA of first period TR values.

next()[source]

Calculate ATR for the current bar.

Uses smoothed moving average: ATR = prev_ATR * alpha1 + TR * alpha

once(start, end)[source]

Calculate ATR in runonce mode.

frompackages = ()
packages = ()
backtrader.indicators.atr.TR

alias of TrueRange

backtrader.indicators.atr.ATR

alias of AverageTrueRange