backtrader.indicators.zlema module¶
ZLEMA Indicator Module - Zero Lag Exponential Moving Average.
This module provides the ZLEMA (Zero Lag Exponential Moving Average) indicator which aims to reduce lag in the standard EMA.
- Classes:
ZeroLagExponentialMovingAverage: ZLEMA indicator (aliases: ZLEMA, ZeroLagEma).
示例
- class MyStrategy(bt.Strategy):
- def __init__(self):
self.zlema = bt.indicators.ZLEMA(self.data.close, period=20)
- def next(self):
# Price above ZLEMA indicates uptrend if self.data.close[0] > self.zlema[0]:
self.buy()
# Price below ZLEMA indicates downtrend elif self.data.close[0] < self.zlema[0]:
self.sell()
- class backtrader.indicators.zlema.ZeroLagExponentialMovingAverage[源代码]¶
-
The zero-lag exponential moving average (ZLEMA) is a variation of the EMA which adds a momentum term aiming to reduce lag in the average to track current prices more closely.
- Formula:
lag = (period - 1) / 2
zlema = ema(2 * data - data(-lag))
- alias = ('ZLEMA', 'ZeroLagEma')¶
- __init__(*args, **kwargs)¶
- nextstart()[源代码]¶
Seed ZLEMA calculation with SMA on first valid bar.
Uses SMA of lag-adjusted data for initial seed value.
- next()[源代码]¶
Calculate ZLEMA for the current bar.
Applies EMA to lag-adjusted data: 2 * data - data(-lag).
- once(start, end)[源代码]¶
Calculate ZLEMA in runonce mode.
Applies EMA to lag-adjusted data across all bars.
- frompackages = ()¶
- packages = ()¶