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.
示例
- 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[源代码]¶
基类:
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)¶
- once(start, end)[源代码]¶
Calculate up day values in runonce mode.
Returns max(price_change, 0) for each bar.
- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.rsi.DownDay[源代码]¶
基类:
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()[源代码]¶
Calculate down day value for the current bar.
Returns max(close_period_ago - close, 0).
- once(start, end)[源代码]¶
Calculate down day values in runonce mode.
Returns max(-price_change, 0) for each bar.
- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.rsi.UpDayBool[源代码]¶
基类:
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.
备注
This version returns a bool rather than the difference
- Formula:
upday = close > close_prev
- See:
- __init__(*args, **kwargs)¶
- next()[源代码]¶
Check if current bar is an up day.
Returns 1.0 if close > close_period_ago, 0.0 otherwise.
- once(start, end)[源代码]¶
Check for up days in runonce mode.
Returns 1.0 where price increased, 0.0 otherwise.
- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.rsi.DownDayBool[源代码]¶
基类:
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.
备注
This version returns a bool rather than the difference
- Formula:
downday = close_prev > close
- See:
- __init__(*args, **kwargs)¶
- next()[源代码]¶
Check if current bar is a down day.
Returns 1.0 if close_period_ago > close, 0.0 otherwise.
- once(start, end)[源代码]¶
Check for down days in runonce mode.
Returns 1.0 where price decreased, 0.0 otherwise.
- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.rsi.RelativeStrengthIndex[源代码]¶
基类:
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
备注
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)[源代码]¶
Calculate RSI in runonce mode.
Computes RSI values across all bars with safe division handling.
- frompackages = ()¶
- packages = ()¶
- backtrader.indicators.rsi.RSI¶
- class backtrader.indicators.rsi.RSI_Safe[源代码]¶
-
Subclass of RSI which changes parameers
safedivtoTrueas the default value- frompackages = ()¶
- packages = ()¶
- class backtrader.indicators.rsi.RSI_SMA[源代码]¶
-
Uses a SimpleMovingAverage as described in Wikipedia and other soures
- alias = ('RSI_Cutler',)¶
- frompackages = ()¶
- packages = ()¶