backtrader.indicators.dma module

DMA Indicator Module - Dickson Moving Average.

This module provides the Dickson Moving Average (DMA) developed by Nathan Dickson, combining ZeroLag and Hull moving averages.

Classes:

DicksonMovingAverage: DMA indicator (aliases: DMA, DicksonMA).

示例

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

self.dma = bt.indicators.DMA(self.data.close, period=20, gainlimit=50, hperiod=7)

def next(self):
if self.data.close[0] > self.dma[0]:

self.buy()

elif self.data.close[0] < self.dma[0]:

self.sell()

class backtrader.indicators.dma.DicksonMovingAverage[源代码]

基类:MovingAverageBase

By Nathan Dickson

The Dickson Moving Average combines the ZeroLagIndicator (aka ErrorCorrecting or EC) by Ehlers, and the HullMovingAverage to try to deliver a result close to that of the Jurik Moving Averages

Formula:
  • ec = ZeroLagIndicator(period, gainlimit)

  • hma = HullMovingAverage(hperiod)

  • dma = (ec + hma) / 2

  • The default moving average for the ZeroLagIndicator is EMA, but can be changed with the parameter _movav

    ::note:: the passed moving average must calculate alpha (and 1 - alpha)

    and make them available as attributes alpha and alpha1

  • The second moving average can be changed from Hull to anything else with the param _hma

alias = ('DMA', 'DicksonMA')
__init__(*args, **kwargs)
next()[源代码]

Calculate DMA for the current bar.

Formula: DMA = (ZeroLag + HMA) / 2

once(start, end)[源代码]

Calculate DMA in runonce mode.

frompackages = ()
packages = ()