logo

Candleverse

Start free

RSI 102: How do you calculate RSI?

Understanding how RSI is calculated will help you better understand the value that the indicator mathematically represents. The more you increase your understanding of RSI, the better you will understand how to trade it. Below is a step by step guide on how to calculate RSI as intended by its creator, J. Welles Wilder.

RSI Calculation:

n = period length

AvgU = average of all up moves in the last n price candles

AvgD = average of all down moves in the last n price candles

Relative Strength = SMMA(AvgU) / SMMA(AvgD)

RSI = 100 – (100 / [1 + Relative Strength ] )

Selecting your period length

The period length will determine how stable or volatile RSI will be and how fast it will react to changing market conditions. In mathematical terms, the length will show you how far back in the past to look in order to calculate the current RSI value. To visually show you what that looks like, I’ve pulled the RSI as it shows up as an oscillator with a 14 period and a 5 period.

14 period:

5 period:

As you can see, when you select a shorter period, the RSI will reach extreme values(above 70 or below 30) more often, making the line appear unstable and volatile. On the contrary, the longer the period the more stable and smoother the line is.

There is no “right” or “best” period to use. You should use the period that makes sense based on your data and trading style. The most popular period length is 14 as suggested by the creator of the RSI and used as the default in the Candleverse.

Calculating the up and down changes

The first step in our calculation involves finding the change in price from the open to the close. The aim of this is to find out how much upward or downward force happened each candle.

Amount Change = Open Price - Close Price

I have an example set of data to visually show what that looks like:

Next, we are going to create 2 more columns to track our up and down changes. You will need to do this for each of the last n, period length, candles. If the value in the “Amount Change” column is positive then we will put it in the “Up” column and if it is negative then we will put the absolute value of it into the “Down” column.

For example, an amount change of -1 will have an “Up” value of 0 and a “Down” value of 1.

Here is our updated example set:

Calculating the SMMA of up and down changes

SMMA, simple or modified moving average, starts by calculating the simple moving average and then moves to a modified moving average for the rest of the calculation because SMMA is a recursive calculation and relies on the previous value to start.

Let’s start with the calculation of simple moving average value. We are going to use the same period length, 14, and we will therefore need the first 14 values of “Up” and “Down” changes. Calculate the average of those 14 values, once for the “Up” values and once for the “Down” values and place them in the candle 14 row as shown below:

AvgU = Average Of Last 14 Values(Change Up)

AvgD = Average Of Last 14 Values(Change Down)

Now that we have the first value, we can use it as the first SMMA to calculate the subsequent SMMA values by using the formula:

SMMA(AvgU(i)) = (Up Change(i) + SMMA(AvgU(i-1))*(14-1))/14

SMMA(AvgD(i)) = (Down Change(i) + SMMA(AvgD(i-1))*(14-1))/14

Calculating the Relative Strength

The term relative strength comes from the fact that the RSI indicator is based on price action changes and not the actual price. In order to calculate the relative strength we need to divide the SMMA of the up changes by the SMMA of the down changes as shown below:

Relative Strength = SMMA(AvgU) / SMMA(AvgD)

Calculating the RSI Value

Now that we have all the values we can follow the equation from the start of this post.

RSI = 100 – (100 / [1 + Relative Strength] )

The RSI for our 14th candle is 67.

The RSI for our 15th candle is 71.

The RSI for our 16th candle is 66.

The result of RSI will always be between 0 and 100. A high RSI will mean that recent moves up have been much greater than the recent moves down and likely indicative of a bullish or overbought market. Conversely, a low RSI will mean that relative strength is low and recent moves down have been much greater than recent moves up resulting in a bearish or possibly oversold market.

If no down moves have occurred and the average down is 0 then relative strength cannot be calculated and RSI is 100.

Hopefully, walking through how to calculate RSI has given you a better understanding of the math behind the logic and how different period lengths can impact results. Go forth and trade responsibly.

Check out the next blog in the RSI series - RSI 103: How do you trade RSI?

logo

Candleverse

Seattle - Amsterdam