The Relative Strength Index is a technical oscillator created by J. Welles Wilder in his 1978 book, New Concepts in Technical Trading Systems. It ranges from 0 to 100, with values below 30 typically considered oversold and above 70 overbought.
RSI myRSI14 = new RSI(bars.Close, 14);
RSI myRSI20 = RSI.Series(bars.Close, 20);
For each trading period, an upward change (U) or downward change (D) is calculated. Up periods are characterized by the close being higher than the previous close:
U = closing price - previous closing price
D = 0
The down period is characterized by the close being lower than the previous period's close (note that D is nonetheless a positive number):
U = 0
D = previous closing price - closing price
If the last close is the same as the previous, both U and D are zero. The average U and D are calculated using an n-period exponentially smoothed Moving Average with a = 1 / period. The ratio of these averages is the relative strength or relative strength factor:
RS = SMMA(U, period) / SMMA(D, period)
The relative strength factor is then converted to a relative strength index between 0 and 100:
RSI = 100 - (100 / (1 + RS))
Use the slider to change the RSI period. The RSI pane is colored redder as prices get more overbought, and greener as prices get more oversold.