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).

示例

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[源代码]

基类: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()[源代码]

Calculate true high: max(high, previous_close).

once(start, end)[源代码]

Calculate true high in runonce mode.

frompackages = ()
packages = ()
class backtrader.indicators.atr.TrueLow[源代码]

基类: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()[源代码]

Calculate true low: min(low, previous_close).

once(start, end)[源代码]

Calculate true low in runonce mode.

frompackages = ()
packages = ()
class backtrader.indicators.atr.TrueRange[源代码]

基类: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()[源代码]

Calculate true range: truehigh - truelow.

once(start, end)[源代码]

Calculate true range in runonce mode.

frompackages = ()
packages = ()
class backtrader.indicators.atr.AverageTrueRange[源代码]

基类: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()[源代码]

Seed ATR with SMA of first period TR values.

next()[源代码]

Calculate ATR for the current bar.

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

once(start, end)[源代码]

Calculate ATR in runonce mode.

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

TrueRange 的别名

backtrader.indicators.atr.ATR

AverageTrueRange 的别名