indicatorData.ema.description
indicatorData.ema.description
indicatorData.ema.strategyContext
En savoir plus sur Trend Following Strategies →import backtrader as bt
class EMATrendFollowing(bt.Strategy):
params = (('fast', 12), ('slow', 26))
def __init__(self):
self.ema_fast = bt.indicators.EMA(self.data.close, period=self.p.fast)
self.ema_slow = bt.indicators.EMA(self.data.close, period=self.p.slow)
self.crossover = bt.indicators.CrossOver(self.ema_fast, self.ema_slow)
def next(self):
if self.crossover > 0: # Fast EMA crosses above slow EMA
self.buy()
elif self.crossover < 0: # Fast EMA crosses below slow EMA
self.sell()| Paramètre | Par défaut | Description |
|---|---|---|
| period | 12 | indicatorData.ema.params.period |