To reproduce RSI, retain its price changes and both smoothed states. A chart labelled RSI 14 may differ because of source data, initialization or a zero-denominator convention. Here we work from a complete hypothetical price sequence, then distinguish rounding a displayed value from rounding the stored state.

What the RSI is actually built from

For closing prices C, define Δ = Cₜ − Cₜ₋₁, upward change U = max(Δ,0) and loss magnitude D = max(−Δ,0). U and D are non-negative; an unchanged price gives both zero. These are price-unit changes, not percentage returns. RSI compares their smoothed magnitudes, not the fraction of rising sessions or participants’ motives.

Define the state before the final reading
G, smoothed gainAfter the seed: ((n−1)Gprevious + U)/n
L, smoothed loss magnitudeAfter the seed: ((n−1)Lprevious + D)/n
RS, if L > 0G/L
RSI, if G + L > 0100 G/(G + L)

Initialization uses arithmetic means of the first n changes. With prices C₀ onward, n changes need n + 1 prices: n = 14 needs 15 closes. Subsequent results carry the earlier state rather than discarding the oldest change and rebuilding a simple last-n mean. An already running platform can have history preceding the displayed chart.

Two decimals can erase RSI's memory

Before the next candle, assume Wilder averages G=L=0.0045 and n=3. Price rises0.001. Preserving exact state gives RSI about 52.63. Storing both averages to two decimals first makes both zero.

Scroll sideways to see the full diagram

Stored-state precision changes RSIThe same price change gives RSI52.63 with precise averages. Rounding both averages to zero yields a positive new gain average and zero loss average, giving RSI100.Rounding state changes the resultn3 · G=L0.0045 · Δ+0.001Full precisionState to 2 decimalsG′=0.003333…G=L=0L′=0.003L′=0RSI=52.63RSI=100050100Shorten the label; preserve the state.
This demonstrates two state-storage methods; it does not allege a particular platform error.

Exactly: G′=(2×0.0045+0.001)/3; L′=(2×0.0045)/3. RSI may be displayed to two decimals, but do not use a shortened label as the next calculation's state. When comparing a spreadsheet with a platform, first check stored-average precision.

Assumptions: Arbitrary averages and price change; Wilder update weight1/3. The incorrect variant rounds G and L before updating; positive G with zero L gives RSI100. Formula or data verification: TradingView: RSI formula.

Wilder smoothing, step by step

In the specified Wilder-style variant, Gₜ = ((n−1)Gₜ₋₁ + Uₜ)/n and Lₜ = ((n−1)Lₜ₋₁ + Dₜ)/n. The new-observation weight is 1/n. For positive L the familiar 100 − 100/(1 + G/L) equals 100 G/(G + L). At G = L > 0, RSI is 50; this does not establish a price range.

For n = 14, the Wilder gain/loss weight is 1/14 ≈ 0.07143, while a conventional EMA14 weight is 2/15 ≈ 0.13333. These are different recursions. They do not imply that every RSI change requires several directional bars, or that a particular alternate RSI has more extreme readings. Compare the exact source and initialization.

A complete calculation from seven prices

Use n = 3 only for a short worked example. Assign arbitrary closes 100,102,101,104,103,103,105, with no earlier state, gaps or extra unstable period. These are not RSI 14 values or a recommended setting.

Hypothetical RSI 3, arithmetic initialization then Wilder updates
Time / closeChange; U; DG; LRSI
t0 / 100Starting priceNo stateNone
t1 / 102+2; 2; 0Collecting changesNone
t2 / 101−1; 0; 1Collecting changesNone
t3 / 104+3; 3; 05/3; 1/383.3333
t4 / 103−1; 0; 110/9; 5/966.6667
t5 / 1030; 0; 020/27; 10/2766.6667
t6 / 105+2; 2; 094/81; 20/8182.4561

At t3, gain total is 5 and absolute loss total 1; divide both by 3, including zero components. At t4, G = (2×5/3 + 0)/3 = 10/9 and L = (2×1/3 + 1)/3 = 5/9, giving RSI 100×10/15 ≈ 66.6667. A rolling window of the latest three changes −1,+3,−1 instead gives G = 1, L = 2/3 and RSI 60. That difference is algorithmic, not display rounding.

At t5, zero change scales both states by 2/3: G = 20/27 and L = 10/27, leaving their ratio and RSI unchanged. At t6, G = 94/81 and L = 20/81, so RSI = 100×94/114 ≈ 82.4561. A flat candle does not automatically reset the result to 50. The fractions are exact; decimals are displayed to four places.

Zero total: specify the code version

With G + L > 0, positive G and zero L give 100; zero G and positive L give 0. Both zero yield 0/0, which the formula does not resolve. The pinned C TA-Lib 0.6.4 code returns 0 for a zero or sufficiently near-zero total. The official MQL4 custom-indicator example returns 50 for exactly zero gains and losses. These are selected code conventions, not every MetaTrader built-in version.

Separate RSI 3 seed examples, four assigned prices each
100,101,102,103G = 1, L = 0; RSI 100
103,102,101,100G = 0, L = 1; RSI 0
100,100,100,100G = L = 0; version 0.6.4 returns 0, the MQL4 example 50

The currently read main branch of TA-Lib uses an exact positive-total test and returns 50 for both-zero states, unlike release 0.6.4. A mutable main-branch URL therefore does not identify the same algorithm permanently. Save code version and source hash with the result. Missing prices, exact zero and small positive states need separate handling; filling a missing price with zero would create an artificial price fall.

Flat RSI can hide changed sensitivity

In a separate assigned RSI 3 state, start at G = L = 1. After k flat changes both equal g = (2/3)k, so RSI remains 50. Then apply one price rise of exactly 1 unit: G′ = (2 g + 1)/3, L′ = 2 g/3, and RSI′ = 100(2 g + 1)/(4 g + 1).

Identical next rise, different stored scales
No preceding flat changes: g = 1RSI 50 → 60 after +1
Six flat changes: g = 64/729RSI 50 → 100×857/985 ≈ 87.0051 after +1

The same visible 50 is insufficient to continue the calculation: both G and L matter. This is an exact property of the assigned recursion, not evidence of a profitable trade after consolidation.

Separate calculation from interpretation

Traditional 70/30 zones and alternative thresholds are interpretation choices. They do not alter the underlying RSI formula or prove profitable performance. ChartSchool describes Brown/Cardwell interpretations of RSI ranges. They are separate conventions, rather than a requirement to switch thresholds whenever a moving-average condition changes.

  • Regular bullish: a lower price low paired with a higher RSI low under declared point rules.
  • Regular bearish: a higher price high paired with a lower RSI high.
  • Hidden bullish: a higher price low paired with a lower RSI low; no continuation is guaranteed.
  • Hidden bearish: a lower price high paired with a higher RSI high; no continuation is guaranteed.

Regular divergence is conventionally associated with possible reversal and hidden divergence with possible continuation. Neither label proves superior profitability. Evaluate precisely defined variants under the same data and cost assumptions.

Wilder RSI compares recursively smoothed gains and losses. Thresholds are conventions rather than automatic orders.

Checks before comparing implementations

Compare the same provider, symbol, applied price, bar interval, timestamps and close status. Retain initialization, intermediate precision and source version. Check these concrete discrepancies before calling either implementation incorrect.

  • Window versus recurrence. Recalculating a plain last-n mean changes the method. Our t4 example gives 60 rather than 66.6667.
  • Version and precision. Exact zero, near-zero thresholds and actual stored-state rounding can change the output. Display formatting alone need not do so.
  • Information time. If the rule uses a closed bar, its final Close and RSI are available only after close and receipt. An intrabar reading is different.

Three layers worth keeping in mind

For identical later price changes, a difference between two G seeds shrinks each step by (n−1)/n; the same holds for L. The difference between their final RSI ratios need not shrink by exactly that factor. Reproduce the states, not a universal number of warm-up bars. A change in source history can change an apparently identical RSI 14.

Calculation, display and strategy evaluation are separate tasks. First match U/D, G/L and version-specific zero rules; then verify when each value became known. Only afterward evaluate the complete entry/exit rule and costs. A correct oscillator value is not a proof of trading efficacy.

What to do tomorrow with the RSI

  1. Save the algorithm. Include initialization, period, price source, source hash and zero-case convention with exported observations.
  2. Compare the worked sequence. Reproduce the exact fractions from the seven prices before testing arbitrary thresholds. Do not use rounded labels as state.
  3. Keep unused evaluation data. A five-pattern sample or month of observations cannot certify an edge. Define points, decision times, execution and costs separately.
  4. Compare the calculations. Fourteen price changes require at least fifteen closes. To reproduce an existing Wilder RSI, also obtain its prior smoothed state or sufficient earlier history under the same initialization. A simple fourteen-change average is a different calculation.

Related reading: RSI — reading the scale, thresholds and closed bars introduces observation rules; MACD — mechanics and parameters explains another calculation; RSI and MACD divergence examines point-selection and timing. A related lesson’s example is separate from evidence of this article’s trading efficacy.