Guia de Indicadores Backtrader

Backtrader RSI Mean Reversion Strategy

indicatorData.rsi.description

bt.indicators.RSIMean Reversion Strategies

indicatorData.rsi.description

indicatorData.rsi.strategyContext

Saiba mais sobre Mean Reversion Strategies →
Pythonbacktrader
import backtrader as bt

class RSIMeanReversion(bt.Strategy):
    params = (('rsi_period', 14), ('rsi_overbought', 70), ('rsi_oversold', 30))

    def __init__(self):
        self.rsi = bt.indicators.RSI(self.data.close, period=self.p.rsi_period)

    def next(self):
        if self.rsi[0] < self.p.rsi_oversold and not self.position:
            self.buy()  # Oversold: expect mean reversion upward
        elif self.rsi[0] > self.p.rsi_overbought and self.position:
            self.sell()  # Overbought: exit on reversion
ParâmetroPadrãoDescrição
period14indicatorData.rsi.params.period
upperband70indicatorData.rsi.params.upperband
lowerband30indicatorData.rsi.params.lowerband