Skip to content
Calculators

RSI and stochasticFree calculator

RSI indicator formula, worked out by hand

RSI = 100 - 100 / (1 + RS), with RS the smoothed average gain over average loss

15 closesSmoothing ruleCalculatorChecked 6 Dec 2026

Example chart with the RSI indicator formula plotted in a lower panel, rising through 70 as price recovers

The RSI indicator formula is RSI = 100 - 100 / (1 + RS), where RS is the average gain divided by the average loss over the last 14 closes. That is the whole idea. The only tricky part is how the two averages are kept up to date, and that is what changes the number on your screen from bar to bar.

Below you will find the formula in plain steps, a complete example with 15 closing prices and every subtraction shown, the next two bars of smoothing, and a calculator above that repeats the work for any prices you paste in.

Quick read

  • Formula

    RSI = 100 - 100 / (1 + RS)
  • RS

    Average gain / average loss over n bars
  • Default n

    14 bars, so 15 closes for the first value
  • First averages

    Plain averages of the first 14 gains and 14 losses
  • After that

    (previous x 13 + current) / 14
  • Example result

    73.21 on bar 15 of our worked set

The RSI indicator formula in four lines

Change = close today - close yesterday
Gain = change if positive, else 0. Loss = minus the change if negative, else 0
RS = average gain / average loss
RSI = 100 - 100 / (1 + RS)

Losses are written as positive numbers. A drop of 0.25 is a loss of 0.25, not -0.25. If you leave the minus sign in, RS turns negative and the result is nonsense.

The first average gain is simply the sum of the first 14 gains divided by 14, and the same for losses. From the next bar on, both averages roll forward with a smoothing rule instead of a fresh 14 bar window:

New average gain = (previous average gain x 13 + today's gain) / 14
New average loss = (previous average loss x 13 + today's loss) / 14

This is the same math as the smoothed moving average, an EMA with a weight of 1/14 on the newest value. It is why RSI moves calmly and why an old price spike fades slowly instead of dropping out of the window all at once.

How to use the RSI calculator above

Enter your closes in the box, one on each line or with commas between them, set the length (leave it at 14 to match the default), and press calculate. The table shows the change, gain, loss, both averages and RSI for every bar, and the working for the last bar is printed underneath so you can follow each number.

Try it with the 15 closes from the table below plus two more, 62.20 and 62.75. The calculator should print 73.21 on bar 15, 67.98 on bar 16 and 71.05 on bar 17. If you get other numbers, check that no close was typed twice and that the length is 14. The load example button fills in 20 sample closes if you only want to see how the output looks.

The first RSI value needs one close more than the length. With length 14 you need at least 15 closes, and the first 14 rows of the output stay empty.

Worked example: RSI from 15 closing prices

Here are 15 made-up daily closes of a stock-like market. Each row subtracts the close before it, then sorts the change into the gain column or the loss column.

15 closes give 14 changes
BarCloseChangeGainLoss
160.00
260.40+0.400.400.00
360.15-0.250.000.25
460.80+0.650.650.00
561.20+0.400.400.00
660.90-0.300.000.30
761.35+0.450.450.00
861.60+0.250.250.00
961.10-0.500.000.50
1061.75+0.650.650.00
1162.05+0.300.300.00
1261.80-0.250.000.25
1362.30+0.500.500.00
1462.10-0.200.000.20
1562.60+0.500.500.00
Total4.101.50
  1. Average gain = 4.10 / 14 = 0.29286
  2. Average loss = 1.50 / 14 = 0.10714
  3. RS = 0.29286 / 0.10714 = 2.7333
  4. RSI = 100 - 100 / (1 + 2.7333) = 100 - 26.79 = 73.21

Nine of the 14 changes were up, and they were larger on average than the five down moves, so RSI lands above 70. We checked every figure in this example against an independent script that follows the same rules.

Column chart of the 14 price changes in the RSI indicator formula example, gains in green and losses in red
Nine gains and five losses: the gains total 4.10 and the losses 1.50.

Bars 16 and 17: the smoothing step in numbers

Bar 16 closes at 62.20, a fall of 0.40. So today's gain is 0 and today's loss is 0.40.

Average gain = (0.29286 x 13 + 0) / 14 = 0.27194
Average loss = (0.10714 x 13 + 0.40) / 14 = 0.12806
RS = 2.1235, RSI = 100 - 100 / 3.1235 = 67.98

Bar 17 closes at 62.75, a rise of 0.55:

Average gain = (0.27194 x 13 + 0.55) / 14 = 0.29180
Average loss = (0.12806 x 13 + 0) / 14 = 0.11891
RS = 2.4539, RSI = 71.05

Notice what did not happen on bar 16. The oldest change in the window (the +0.40 on bar 2) was not dropped. In this method nothing is ever dropped; old moves just shrink in weight by 13/14 each bar. One sharp day therefore keeps nudging the reading for weeks.

Why your charting app may show a different RSI

Because each average builds on the one before it, the RSI value depends on where the calculation started. Your charting app may begin from the first bar it has loaded, which can be hundreds of bars back. A hand calculation that starts 15 closes ago will not match at first.

We tested this on a made-up series of 250 bars. RSI 14 started on bar 1 and RSI 14 started on bar 51 differed by 4.32 points on bar 71, by 0.44 on bar 101 and by only 0.01 on bar 151. The gap closes, but it takes around 100 bars to become too small to see.

BarStarted on bar 1Started on bar 51Gap
7153.0457.364.32
8145.5447.602.07
10157.2857.720.44
15152.3052.310.01

A second source of mismatch: some versions replace the smoothing with plain 14 bar averages of gains and losses. On our bar 16 that version gives 66.07 instead of 67.98. Neither is wrong, but they are different indicators wearing the same name, so compare like with like.

From RS to RSI: what the number means

RSI is just RS squeezed onto a scale of 0 to 100. Equal average gains and losses (RS = 1) give exactly 50. The table shows how fast the scale bends near its ends.

RS (gain / loss)RSIIn words
0.2520.0Average loss is four times the average gain
0.4330.0The classic oversold line
1.0050.0Gains and losses balance
2.3370.0The classic overbought line
4.0080.0Gains four times the losses
9.0090.0Almost one way traffic

To reach 70, average gains must be about 2.33 times the average losses. To get from 80 to 90, RS has to more than double again. That is why readings above 90 or below 10 are rare on a 14 bar setting. How traders act on 70 and 30 is covered on the RSI buy and sell signals page, and other lengths on RSI settings.

Where the arithmetic misleads

The formula only looks at closes. A bar that spikes far up and closes flat adds nothing to the gains. Gaps count fully, so one gap can lift RSI by many points. And the reading says how one sided recent closes were, not whether price is cheap or expensive. In our example RSI was 73.21 after a steady climb, yet nothing in the math says the climb must stop there.

A high RSI is a description of the past 14 bars, not a forecast. In strong trends RSI can sit above 70 for many bars while price keeps rising. Treat it as one input next to price structure, such as support and resistance.

Borrowed money magnifies every miss: a leveraged position can cost more than you planned, and the majority of retail accounts trading forex or CFDs on margin end up behind. Rehearse on a demo account or old charts before anything else. Everything here is general education, not financial advice; the technical analysis glossary at Investor.gov covers the wider method. For the bigger picture of the tool, start at the RSI indicator guide.

Questions traders ask

How do you calculate RSI by hand?

List 15 closes, write down the 14 changes, and split them into gains and losses with losses as positive numbers. Average each column over 14, divide gains by losses to get RS, then compute 100 - 100 / (1 + RS). After that, update both averages with the smoothing rule each new bar.

Why does RSI use 14 periods?

Fourteen is the long standing default that most charting apps load. It is a convention, not a law. Shorter lengths react faster and reach 70 and 30 more often; longer lengths move more slowly.

Can RSI reach 100 or 0?

Only if every change in the averages is a gain (RSI 100) or every change is a loss (RSI 0). With smoothing, one losing bar is enough to pull RSI below 100, so exact extremes are rare outside very short lengths.

What happens if the average loss is zero?

RS would mean dividing by zero, so calculators set RSI to 100 in that case. Our calculator above does the same.

Is RSI the same as comparing a stock with an index?

No. That comparison is often called relative strength too, but it divides one market by another. RSI looks at a single market and compares its own up closes with its own down closes.