indicatorData.bollinger_bands.description
indicatorData.bollinger_bands.description
indicatorData.bollinger_bands.strategyContext
Saiba mais sobre Breakout Trading Strategies →import backtrader as bt
class BollingerBreakout(bt.Strategy):
params = (('period', 20), ('devfactor', 2.0))
def __init__(self):
self.bb = bt.indicators.BollingerBands(self.data.close,
period=self.p.period,
devfactor=self.p.devfactor)
def next(self):
# Price breaks above upper band = bullish breakout
if self.data.close[0] > self.bb.lines.top[0] and self.data.close[-1] <= self.bb.lines.top[-1]:
self.buy()
# Price breaks below lower band = bearish breakout
elif self.data.close[0] < self.bb.lines.bot[0] and self.data.close[-1] >= self.bb.lines.bot[-1]:
self.sell()| Parâmetro | Padrão | Descrição |
|---|---|---|
| period | 20 | indicatorData.bollinger_bands.params.period |
| devfactor | 2 | indicatorData.bollinger_bands.params.devfactor |