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[源代码]¶
基类:
IndicatorDefined 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)¶
- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.atr.TrueLow[源代码]¶
基类:
IndicatorDefined 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)¶
- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.atr.TrueRange[源代码]¶
基类:
IndicatorDefined 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)¶
- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.atr.AverageTrueRange[源代码]¶
基类:
IndicatorDefined 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)¶
- next()[源代码]¶
Calculate ATR for the current bar.
Uses smoothed moving average: ATR = prev_ATR * alpha1 + TR * alpha
- frompackages = ()¶
- packages = ()¶
- backtrader.indicators.atr.ATR¶
AverageTrueRange的别名