backtrader.indicators.zlind module

Zero Lag Indicator Module - Zero-lag error correction.

This module provides the ZeroLagIndicator developed by John Ehlers and Ric Way to reduce lag in moving averages.

Classes:

ZeroLagIndicator: Zero-lag indicator with error correction.

示例

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

self.zlind = bt.indicators.ZeroLagIndicator(self.data.close, period=20, gainlimit=50)

def next(self):

# Price above ZeroLagIndicator indicates uptrend if self.data.close[0] > self.zlind[0]:

self.buy()

# Price below ZeroLagIndicator indicates downtrend elif self.data.close[0] < self.zlind[0]:

self.sell()

class backtrader.indicators.zlind.ZeroLagIndicator[源代码]

基类:MovingAverageBase

By John Ehlers and Ric Way

The zero-lag indicator (ZLIndicator) is a variation of the EMA which modifies the EMA by trying to minimize the error (distance price - error correction) and thus reduce the lag

Formula:
  • EMA(data, period)

  • For each iteration calculate a best-error-correction of the ema (see the paper and/or the code) iterating over -bestgain -> +bestgain for the error correction factor (both incl.)

  • The default moving average 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 in the instance

alias = ('ZLIndicator', 'ZLInd', 'EC', 'ErrorCorrecting')
__init__(*args, **kwargs)
next()[源代码]

Calculate zero lag indicator for the current bar.

Iterates over gain values to find the error correction that minimizes the difference between price and corrected EMA.

frompackages = ()
once(start, end)

Implement once using next for batch calculation.

This is used when next is overridden but once is not. It loops through the range and calls next for each step.

参数:
  • start -- Starting index

  • end -- Ending index

oncestart(start, end)

Implement oncestart using nextstart for batch calculation.

This is used when nextstart is overridden but oncestart is not.

参数:
  • start -- Starting index

  • end -- Ending index

packages = ()
preonce(start, end)

Implement preonce using prenext for batch calculation.

This is a generic implementation if prenext is overridden but preonce is not. It loops through the range and calls prenext for each step.

参数:
  • start -- Starting index

  • end -- Ending index