indicatorData.macd.description
indicatorData.macd.description
indicatorData.macd.strategyContext
Saiba mais sobre Momentum Trading Strategies →import backtrader as bt
class MACDMomentum(bt.Strategy):
params = (('fast', 12), ('slow', 26), ('signal', 9))
def __init__(self):
self.macd = bt.indicators.MACD(self.data.close,
period_me1=self.p.fast,
period_me2=self.p.slow,
period_signal=self.p.signal)
def next(self):
# MACD line crosses above signal line = bullish momentum
if self.macd.macd[0] > self.macd.signal[0] and self.macd.macd[-1] <= self.macd.signal[-1]:
self.buy()
# MACD line crosses below signal line = bearish momentum
elif self.macd.macd[0] < self.macd.signal[0] and self.macd.macd[-1] >= self.macd.signal[-1]:
self.sell()| Parâmetro | Padrão | Descrição |
|---|---|---|
| period_me1 | 12 | indicatorData.macd.params.period_me1 |
| period_me2 | 26 | indicatorData.macd.params.period_me2 |
| period_signal | 9 | indicatorData.macd.params.period_signal |