backtrader.indicators.rsi module¶
RSI Indicator Module - Relative Strength Index.
This module provides the RSI (Relative Strength Index) indicator developed by J. Welles Wilder, Jr.
- Classes:
RSI: RSI indicator. UpDay/DownDay: Helper classes for RSI calculation.
Example
- class MyStrategy(bt.Strategy):
- def __init__(self):
self.rsi = bt.indicators.RSI(self.data.close, period=14)
- def next(self):
# RSI above 70 indicates overbought if self.rsi.rsi[0] > 70:
self.sell()
# RSI below 30 indicates oversold elif self.rsi.rsi[0] < 30:
self.buy()
- class backtrader.indicators.rsi.UpDay[source]¶
Bases:
IndicatorDefined by J. Welles Wilder, Jr. in 1978 in his book “New Concepts in Technical Trading Systems” for the RSI
Records days which have been “up”, i.e.: the close price has been higher than the day before.
- Formula:
upday = max (close - close_prev, 0)
- See:
- __init__(*args, **kwargs)¶
- next()[source]¶
Calculate up day value for the current bar.
Returns max(close - close_period_ago, 0).
- once(start, end)[source]¶
Calculate up day values in runonce mode.
Returns max(price_change, 0) for each bar.
- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.rsi.DownDay[source]¶
Bases:
IndicatorDefined by J. Welles Wilder, Jr. in 1978 in his book “New Concepts in Technical Trading Systems” for the RSI
Records days which have been “down”, i.e.: the close price has been lower than the day before.
- Formula:
downday = max(close_prev - close, 0)
- See:
- __init__(*args, **kwargs)¶
- next()[source]¶
Calculate down day value for the current bar.
Returns max(close_period_ago - close, 0).
- once(start, end)[source]¶
Calculate down day values in runonce mode.
Returns max(-price_change, 0) for each bar.
- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.rsi.UpDayBool[source]¶
Bases:
IndicatorDefined by J. Welles Wilder, Jr. in 1978 in his book “New Concepts in Technical Trading Systems” for the RSI
Records days which have been “up”, i.e.: the close price has been higher than the day before.
Note
This version returns a bool rather than the difference
- Formula:
upday = close > close_prev
- See:
- __init__(*args, **kwargs)¶
- next()[source]¶
Check if current bar is an up day.
Returns 1.0 if close > close_period_ago, 0.0 otherwise.
- once(start, end)[source]¶
Check for up days in runonce mode.
Returns 1.0 where price increased, 0.0 otherwise.
- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.rsi.DownDayBool[source]¶
Bases:
IndicatorDefined by J. Welles Wilder, Jr. in 1978 in his book “New Concepts in Technical Trading Systems” for the RSI
Records days which have been “down”, i.e.: the close price has been lower than the day before.
Note
This version returns a bool rather than the difference
- Formula:
downday = close_prev > close
- See:
- __init__(*args, **kwargs)¶
- next()[source]¶
Check if current bar is a down day.
Returns 1.0 if close_period_ago > close, 0.0 otherwise.
- once(start, end)[source]¶
Check for down days in runonce mode.
Returns 1.0 where price decreased, 0.0 otherwise.
- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.rsi.RelativeStrengthIndex[source]¶
Bases:
IndicatorDefined by J. Welles Wilder, Jr. in 1978 in his book “New Concepts in Technical Trading Systems”.
It measures momentum by calculating the ration of higher closes and lower closes after having been smoothed by an average, normalizing the result between 0 and 100
- Formula:
up = upday(data)
down = downday(data)
maup = movingaverage(up, period)
madown = movingaverage(down, period)
rs = maup / madown
rsi = 100 - 100 / (1 + rs)
The moving average used is the one originally defined by Wilder, the SmoothedMovingAverage
Notes
safediv(default: False) If this parameter is True, the division rs = maup / madown will be checked for the special cases in which a0 / 0orx / 0division will happensafehigh(default: 100.0) will be used as RSI value for thex / 0casesafelow(default: 50.0) will be used as RSI value for the0 / 0case
- alias = ('RSI', 'RSI_SMMA', 'RSI_Wilder')¶
- __init__(*args, **kwargs)¶
- once(start, end)[source]¶
Calculate RSI in runonce mode.
Computes RSI values across all bars with safe division handling.
- frompackages = ()¶
- packages = ()¶
- backtrader.indicators.rsi.RSI¶
alias of
RelativeStrengthIndex
- class backtrader.indicators.rsi.RSI_Safe[source]¶
Bases:
RelativeStrengthIndexSubclass of RSI which changes parameers
safedivtoTrueas the default value- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.rsi.RSI_SMA[source]¶
Bases:
RelativeStrengthIndexUses a SimpleMovingAverage as described in Wikipedia and other soures
- alias = ('RSI_Cutler',)¶
- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.rsi.RSI_EMA[source]¶
Bases:
RelativeStrengthIndexUses an ExponentialMovingAverage as described in Wikipedia
- frompackages = ()¶
- packages = ()¶