Backtrader インジケーターガイド

Backtrader Bollinger Bands Breakout Strategy

indicatorData.bollinger_bands.description

bt.indicators.BollingerBandsBreakout Trading Strategies

indicatorData.bollinger_bands.description

indicatorData.bollinger_bands.strategyContext

Breakout Trading Strategies について詳しく学ぶ →
Pythonbacktrader
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()
パラメーターデフォルト説明
period20indicatorData.bollinger_bands.params.period
devfactor2indicatorData.bollinger_bands.params.devfactor