The Relative Strength Index (RSI) compares smoothed gains and losses in a price series. It summarizes recent directional momentum on a scale from 0 to 100. A reading above 50 means the smoothed gains exceed the smoothed losses over the calculation’s effective lookback.
How Wilder’s RSI is calculated
For each completed bar, subtract the previous close from the current close. Record the positive part as the gain and the absolute value of the negative part as the loss. A bar with no change contributes zero to both.
For a lookback of n bars, seed the average gain G and average loss L with the arithmetic means of the first n changes. Each subsequent bar updates them as G = ((n − 1) × previous G + current gain) / n and L = ((n − 1) × previous L + current loss) / n. When G + L > 0, RSI = 100 × G / (G + L). This is equivalent to the usual relative-strength expression wherever the latter is defined. If both averages are zero, check the platform’s convention for a flat series.
Worked example with synthetic prices
Take closes of 100, 102, 101, 104 and 102, using n = 3 to make the arithmetic easy to follow. The first three changes are +2, −1 and +3. At the close of 104, G = 5/3 and L = 1/3, so RSI = 83.33. The last change is −2. The updated G is 10/9 and L is 8/9, so RSI falls to 55.56. Keep full precision until the final display.
What the lookback and thresholds change
Fourteen bars are a common starting point. A shorter lookback makes new changes carry more weight, while a longer lookback smooths them more heavily. Thresholds such as 70 and 30 describe the indicator’s level. In a sustained directional move, RSI can stay beyond a threshold through several bars, so a threshold crossing alone does not establish that a reversal is imminent.
How to test an RSI rule
Specify the price field, timeframe, lookback and whether the rule uses a closed bar. Define entry and exit separately and test on data held out from parameter selection. If combining RSI with another momentum indicator, compare the combined rule with each rule alone under identical costs and execution assumptions. This example illustrates the calculation and contains no performance results.
Implementation and references
To compare a platform output with a hand calculation, use the same price series, bar timestamps, initialization and warm-up history. For MetaTrader 5, see the MetaQuotes iRSI API. For the formula and the smoothing used in TradingView, see TradingView’s RSI documentation.
Leave a Reply