
Momentum oscillator measuring speed and change of price movements on a scale of 0-100. Values above 70 indicate overbought conditions, below 30 indicate oversold conditions.
Momentum oscillator measuring speed and change of price movements on a scale of 0-100. Values above 70 indicate overbought conditions, below 30 indicate oversold conditions.
RSI is the cornerstone of mean reversion strategies. When price deviates significantly from its mean (RSI > 70 or < 30), traders expect a return to equilibrium. Unlike trend-following indicators, RSI thrives in ranging markets where price oscillates around a stable average.
Learn more about Mean Reversion Strategies →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| Parameter | Default | Description |
|---|---|---|
| period | 14 | Lookback period for RSI calculation |
| upperband | 70 | Overbought threshold |
| lowerband | 30 | Oversold threshold |