The Relative Strength Index (RSI) calculates a ratio of the recent upward price movements to the absolute price movement. Developed by J. Welles Wilder.
RSI(price, n = 14, maType, ...)
Price series that is coercible to xts or matrix.
Number of periods for moving averages.
Either:
A function or a string naming the function to be called.
A list with the first component like (1) above, and additional parameters specified as named components. See Examples.
Other arguments to be passed to the maType
function in
case (1) above.
A object of the same class as price
or a vector (if
try.xts
fails) containing the RSI values.
The RSI calculation is RSI = 100 - 100 / ( 1 + RS )
, where RS
is the smoothed ratio of 'average' gains over 'average' losses. The
'averages' aren't true averages, since they're divided by the value of
n
and not the number of periods in which there are gains/losses.
The following site(s) were used to code/document this indicator: Relative Strength Index: https://www.fmlabs.com/reference/RSI.htm https://www.metastock.com/Customer/Resources/TAAZ/?p=100 https://www.linnsoft.com/techind/relative-strength-index-rsi https://school.stockcharts.com/doku.php?id=technical_indicators:relative_strength_index_rsi Stochastic RSI: https://www.fmlabs.com/reference/StochRSI.htm https://school.stockcharts.com/doku.php?id=technical_indicators:stochrsi
See EMA
, SMA
, etc. for moving average
options; and note Warning section. See CMO
for a variation on
RSI.
# NOT RUN {
data(ttrc)
price <- ttrc[,"Close"]
# Default case
rsi <- RSI(price)
# Case of one 'maType' for both MAs
rsiMA1 <- RSI(price, n=14, maType="WMA", wts=ttrc[,"Volume"])
# Case of two different 'maType's for both MAs
rsiMA2 <- RSI(price, n=14, maType=list(maUp=list(EMA),maDown=list(WMA)))
# }
Run the code above in your browser using DataLab