MyAlgoMate
// INDICATOR FORMULA

RSI formula: how to calculate RSI (with Excel)

How the Relative Strength Index is worked out, step by step — Wilder's averages of the up-moves and down-moves in the close over 14 candles, turned into a number between 0 and 100. With a worked example, the Excel formulas, a free Excel sheet and a box to calculate RSI from your own prices.

Last updated:

Download the free RSI Excel sheet (.xlsx)

Needs: closing prices · Standard settings: Period 14

The RSI formula

Change = Close − previous Close
Gain   = Change, if it is above 0 (otherwise 0)
Loss   = −Change, if it is below 0 (otherwise 0)

First average gain = average of the first 14 gains
First average loss = average of the first 14 losses
Next average gain  = (previous average gain × 13 + current gain) ÷ 14
Next average loss  = (previous average loss × 13 + current loss) ÷ 14

RS  = Average gain ÷ Average loss
RSI = 100 − 100 ÷ (1 + RS)

The 13 and 14 come from the period: for RSI n they are n − 1 and n. This running average is Wilder's smoothing (often called RMA), the method J. Welles Wilder published with RSI in 1978 and the one most charts use. If the average loss is 0 — no down candles in the window — RSI is 100.

“Gain” and “loss” are the standard names in the RSI formula for how much the closing price rose or fell from one candle to the next. They are price changes, not anyone's profit or loss.

How to calculate RSI step by step

  1. List the closing prices, oldest first. In the example, Day 1 closed at 1,001.15 and Day 2 at 987.95.
  2. Work out each candle's change and split it into a gain or a loss. Day 2: 987.95 − 1,001.15 = −13.20, so the gain is 0 and the loss is 13.20. Day 3 rose by 21.20, so its gain is 21.20 and its loss is 0.
  3. Average the first 14 gains and the first 14 losses. The first 14 changes are Day 2 to Day 15, so the first averages appear on Day 15: average gain 9.5643, average loss 5.1107.
  4. Turn them into RS and RSI. RS = 9.5643 ÷ 5.1107 = 1.8714, and RSI = 100 − 100 ÷ (1 + 1.8714) = 65.17.
  5. From the next candle on, smooth the averages. Day 16 fell by 33.30: average gain = (9.5643 × 13 + 0) ÷ 14 = 8.8811; average loss = (5.1107 × 13 + 33.30) ÷ 14 = 7.1242. RSI = 55.49.
  6. Repeat for every candle. By Day 60 the example's RSI (14) is 69.67.

Worked example — and calculate RSI from your own prices

The table works through 60 daily candles of an imaginary stock, column by column — the same columns as the Excel sheet. To calculate RSI for your own stock, clear the box and paste your closing prices from Excel or your broker's download.

One row per candle, oldest first. Paste straight from Excel or your broker's download; a date or time column becomes the row label. Filled with our example prices.

Latest values

RSI (14): 69.67
RSI calculated from the example prices
DayCloseChangeGainLossAvg gainAvg lossRSRSI (14)
Day 11,001.15
Day 2987.95−13.200.0013.20
Day 31,009.1521.2021.200.00
Day 41,012.603.453.450.00
Day 5993.25−19.350.0019.35
Day 61,008.6015.3515.350.00
Day 71,013.605.005.000.00
Day 81,001.55−12.050.0012.05
Day 91,031.5530.0030.000.00
Day 101,040.058.508.500.00
Day 111,033.15−6.900.006.90
Day 121,064.8031.6531.650.00
Day 131,083.5518.7518.750.00
Day 141,067.95−15.600.0015.60
Day 151,063.50−4.450.004.459.56435.11071.871465.17
Day 161,030.20−33.300.0033.308.88117.12421.246655.49
Day 171,012.20−18.000.0018.008.24687.90111.043851.07
Day 18981.60−30.600.0030.607.65779.52240.804244.57
Day 19970.55−11.050.0011.057.11079.63150.738342.47
Day 20960.90−9.650.009.656.60289.63290.685440.67
Day 21978.3017.4017.400.007.37408.94480.824445.19
Day 22958.85−19.450.0019.456.84739.69520.706341.39
Day 23946.75−12.100.0012.106.35829.86690.644439.19
Day 24937.95−8.800.008.805.90419.79070.603037.62
Day 25927.85−10.100.0010.105.48249.81280.558735.84
Day 26911.20−16.650.0016.655.090810.30120.494233.07
Day 27905.15−6.050.006.054.72719.99750.472832.10
Day 28885.95−19.200.0019.204.389510.65490.412029.18
Day 29874.70−11.250.0011.254.075910.69740.381027.59
Day 30855.80−18.900.0018.903.784811.28330.335425.12
Day 31862.156.356.350.003.968010.47730.378727.47
Day 32866.454.304.300.003.99179.72890.410329.09
Day 33845.10−21.350.0021.353.706610.55900.351025.98
Day 34851.556.456.450.003.90269.80480.398028.47
Day 35860.208.658.650.004.24179.10450.465931.78
Day 36854.80−5.400.005.403.93878.83990.445630.82
Day 37877.2022.4022.400.005.25748.20840.640539.04
Day 38888.4511.2511.250.005.68547.62210.745942.72
Day 39905.4016.9516.950.006.49007.07770.917047.83
Day 40896.80−8.600.008.606.02657.18640.838645.61
Day 41889.60−7.200.007.205.59607.18740.778643.78
Day 42895.305.705.700.005.60346.67400.839645.64
Day 43919.0023.7023.700.006.89606.19731.112752.67
Day 44918.35−0.650.000.656.40355.80111.103852.47
Day 45906.25−12.100.0012.105.94616.25100.951248.75
Day 46932.1025.8525.850.007.36785.80451.269355.93
Day 47944.3512.2512.250.007.71655.38991.431758.88
Day 48948.704.354.350.007.47605.00491.493759.90
Day 49966.3517.6517.650.008.20284.64741.765063.83
Day 50955.60−10.750.0010.757.61685.08331.498459.97
Day 51969.1013.5013.500.008.03714.72021.702763.00
Day 52984.3515.2515.250.008.55234.38301.951266.12
Day 53980.90−3.450.003.457.94144.31641.839864.79
Day 54962.50−18.400.0018.407.37425.32241.385558.08
Day 55960.20−2.300.002.306.84745.10651.340957.28
Day 56967.357.157.150.006.86904.74171.448659.16
Day 57971.003.653.650.006.63914.40301.507860.13
Day 58981.7510.7510.750.006.93274.08851.695762.90
Day 59994.8513.1013.100.007.37333.79651.942166.01
Day 601,012.3517.5017.500.008.09663.52532.296769.67
Everything is worked out in your browser. Nothing you paste is stored or sent.

The example prices are made up for this page — they are not real market data. RSI is a calculation from past prices, not a forecast, a signal or advice to buy or sell. MyAlgoMate provides trading technology, not investment advice.

How to calculate RSI in Excel

Put the headings in row 1 and the first candle in row 2, oldest at the top. Then type these formulas — each column uses the ones to its left:

  1. A

    Day

    A2 downwards: your dates, oldest at the top.

  2. B

    Close

    B2 downwards: the closing prices, oldest at the top.

  3. C

    Change

    C3 =B3-B2 — then copy it down to the last row.

  4. D

    Gain

    D3 =MAX(C3,0) — then copy it down to the last row.

  5. E

    Loss

    E3 =MAX(-C3,0) — then copy it down to the last row.

  6. F

    Avg gain

    F16 =AVERAGE(D3:D16) — this cell only (the starting value).

    F17 =(F16*13+D17)/14 — then copy it down to the last row.

  7. G

    Avg loss

    G16 =AVERAGE(E3:E16) — this cell only (the starting value).

    G17 =(G16*13+E17)/14 — then copy it down to the last row.

  8. H

    RS

    H16 =IF(G16=0,"",F16/G16) — then copy it down to the last row.

  9. I

    RSI (14)

    I16 =IF(G16=0,100,100-100/(1+F16/G16)) — then copy it down to the last row.

Rows 2 to 15 have no RSI: the first value needs 14 changes. The only difference between row 16 and the rows below it is the averaging — a plain AVERAGE once, then the smoothing formula.

Prefer not to type them? The free sheet has every formula filled in for the example prices — replace the prices with yours and extend the rows. It opens in Microsoft Excel (we checked every value against the table above), and you can import it into Google Sheets or LibreOffice.

Download the free RSI Excel sheet (.xlsx)

What the RSI number shows

RSI compares the size of recent up-moves with recent down-moves on a scale from 0 to 100. At 50 the average gain and the average loss are equal; above 50 the average gain is the larger one, below 50 the average loss is. It reaches 100 only when there were no losses at all in the window, and 0 only when there were no gains.

Many charts draw lines at 70 and 30, the levels commonly labelled “overbought” and “oversold”. They are reference lines on the scale, not instructions — RSI describes past prices, and what you do with it is your own decision.

MACD and RSI: how they differ and how they are read together

Both indicators start from the same closing prices, but they are built differently and describe different things. The table sets them side by side; the full formula for the other one is on the MACD formula page.

 RSI (14)MACD (12, 26, 9)
What it measuresSize of recent up-moves against down-movesGap between a faster and a slower moving average: direction and speed of the trend
Built fromWilder's average gain and average lossTwo exponential averages (EMA 12 and EMA 26) and a 9-candle EMA of their gap
ScaleFixed, 0 to 100No fixed range; moves around a zero line, in price units
Reference lines on charts50, and lines at 30 and 70The zero line and the signal line
PartsOne lineMACD line, signal line, histogram
Both areWorked out from past closing prices only, so both lag the price and neither forecasts it

Side by side, on the same prices.The table below takes four days of this page's imaginary stock and shows both indicators for the same close. It is arithmetic from the worked example, not real market data.

DayCloseRSI (14)MACD lineSignalHistogram
Day 34851.5528.47−49.6827−45.3296−4.3531
Day 40896.8045.61−31.4433−40.39448.9511
Day 50955.6059.972.6206−10.713213.3338
Day 601,012.3569.6717.875811.23176.6442

Across Day 34 to Day 60 of the example (every day where both have a value), RSI is above 50 and the MACD line is above zero, or both are on the other side, on 22 of 27 days. On the other 5 they sit on opposite sides. The two are built from different parts of the price history, so they do not always agree, and a day where they differ is not an error.

People who put both on one chart usually describe it this way: MACD is read for the direction and strength of the trend, RSI for how strong recent up-moves are compared with down-moves. That describes how the indicators are commonly read; it is not a rule, a signal or a recommendation to buy or sell. Neither indicator predicts what price does next.

Why your RSI may not match your chart

  • How much history went in. The smoothing never fully forgets earlier candles, so start from more history than you need — the difference fades as you add candles.
  • Simple averages instead of Wilder's. Some tools (“Cutler's RSI”) use a plain 14-candle average every time; the numbers come out different.
  • Different prices. Spot vs futures, a different timeframe, or a chart that adjusts past prices for splits and bonuses.
  • A different period. RSI 9 or RSI 21 move differently from RSI 14 — check the setting.

Simple-average RSI (Cutler's version)

If you need the simple-average version, replace the two smoothing formulas with plain averages of the last 14:

Average gain = AVERAGE(last 14 gains)
Average loss = AVERAGE(last 14 losses)
RSI = 100 − 100 ÷ (1 + Average gain ÷ Average loss)

In the Excel sheet that means putting =AVERAGE(D3:D16) in F16 and copying it down (and the same for column G). Related: the stochastic formula (used in Stochastic RSI) and the EMA formula, which Wilder's smoothing resembles.

// FAQ

RSI calculation — questions, answered.

Work out each candle's change from the previous close and split it into a gain or a loss. Average the first 14 gains and the first 14 losses, then keep both averages going with Wilder's smoothing: (previous average × 13 + today's value) ÷ 14. RS is the average gain divided by the average loss, and RSI = 100 − 100 ÷ (1 + RS).

Put dates in column A and closes in column B from row 2. In C3 type =B3-B2 (the change), in D3 =MAX(C3,0) (gain) and in E3 =MAX(-C3,0) (loss), and copy them down. The first averages go in row 16: =AVERAGE(D3:D16) and =AVERAGE(E3:E16). From row 17: =(F16*13+D17)/14 and =(G16*13+E17)/14. RSI in I16: =IF(G16=0,100,100-100/(1+F16/G16)), copied down. The free sheet on this page has all of it filled in.

Usually because of the starting point. Wilder's smoothing carries a little of every earlier candle forward, so RSI worked out from 60 candles differs slightly from RSI worked out from 1,000 candles of the same stock — the gap shrinks as you add history. Other causes: a different period, spot vs futures prices, a different timeframe, or a chart that uses simple averages instead of Wilder's smoothing.

At least 15 closes — 14 changes need 15 prices — for the first value. To match a chart closely, use much more history: 100 or more candles before the date you are checking is a sensible amount, because the smoothing needs time to settle.

It is the averaging J. Welles Wilder used when he published RSI in 1978: new average = (previous average × (n − 1) + new value) ÷ n. It works like an exponential moving average with a weight of 1 ÷ n (1 ÷ 14 for RSI 14), so it reacts more slowly than a standard EMA of the same length. Many charting tools call it RMA or SMMA.

Stochastic RSI applies the stochastic formula to RSI values instead of prices: StochRSI = (RSI − lowest RSI of the last 14) ÷ (highest RSI of the last 14 − lowest RSI of the last 14). Charts usually smooth it with a 3-period average (%K) and average that again (%D). So you calculate RSI first, exactly as on this page, then apply the stochastic step to the RSI column.

They measure different things from the same closing prices. MACD is the gap between a 12-candle and a 26-candle exponential average, with a 9-candle signal line, so it follows the direction and speed of the trend and can be above or below zero. RSI compares the size of recent up-moves with recent down-moves and always sits between 0 and 100. MACD has no fixed top or bottom; RSI does. Neither one is a forecast.

Many people put both on one chart because they answer different questions: MACD describes the trend's direction and strength, RSI describes how strong recent up-moves are compared with down-moves. This page only explains how each is calculated and how they are commonly read. It does not tell you when to buy or sell, and a reading from either indicator is not a signal or advice.

Neither is better; they are built differently. MACD is made from moving averages and has no fixed range, RSI is a 0 to 100 scale made from average gains and losses. Both are calculated from past prices and both lag the price. Which one you look at is your own choice.

Yes. The formulas on this page use only basic functions (MAX, AVERAGE, IF), which Google Sheets has too. You can type them in, or import the free .xlsx file into Google Sheets.

More indicator formulas, with Excel sheets

Turn your own rules into automated orders.

Already use RSI in your own rules? MyAlgoMate's algo trading software places the orders your rules call for at 150+ Indian brokers — and TradeBridge turns your own TradingView or Chartink alerts into live orders. You decide the rules; we provide the technology.

Share this page