In this article
After this article, you can
- Distinguish display formatting from stored-value rounding.
- Preserve smoothing state for subsequent RSI updates.
Terms at hand: Relative Strength Index (RSI) · Pip · Balance · Average Directional Index (ADX) · Average True Range (ATR) · MACD (Moving Average Convergence Divergence)
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.
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
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.
| Time / close | Change; U; D | G; L | RSI |
|---|---|---|---|
| t0 / 100 | Starting price | No state | None |
| t1 / 102 | +2; 2; 0 | Collecting changes | None |
| t2 / 101 | −1; 0; 1 | Collecting changes | None |
| t3 / 104 | +3; 3; 0 | 5/3; 1/3 | 83.3333 |
| t4 / 103 | −1; 0; 1 | 10/9; 5/9 | 66.6667 |
| t5 / 103 | 0; 0; 0 | 20/27; 10/27 | 66.6667 |
| t6 / 105 | +2; 2; 0 | 94/81; 20/81 | 82.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.
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).
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
- Save the algorithm. Include initialization, period, price source, source hash and zero-case convention with exported observations.
- Compare the worked sequence. Reproduce the exact fractions from the seven prices before testing arbitrary thresholds. Do not use rounded labels as state.
- Keep unused evaluation data. A five-pattern sample or month of observations cannot certify an edge. Define points, decision times, execution and costs separately.
- 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.
Check your understanding
One short exercise
About 2 min · you can try again
A sheet displays G0.00 but stores0.0045. Must the shortened label change the next RSI?
- Yes; displaying0.00 always erases state.
- No, if the next step uses the full stored value.
- No, even if an actual zero was stored.
Check the answer and explanation
No, if the next step uses the full stored value.
The formula uses0.0045, not the text0.00.
Frequently asked
How many prices are needed to initialize RSI 14?
The stated seed needs 14 changes, hence 15 prices. Fourteen closes give 13 differences. An existing platform can use earlier history beyond the visible chart. This count describes initialization, not a universally best period or a guaranteed number of warm-up observations.
How exactly does Wilder smoothing differ from a plain arithmetic average?
After the arithmetic seed, Wilder updates the prior gain and loss averages using weight 1/n. A plain last-n window recomputes and discards changes, while a conventional EMA uses 2/(n+1). In our RSI 3 model, t4 is 66.6667 with recurrence and 60 with the rolling window. The size of a discrepancy is data-dependent, not universally a few points or one bar.
Does an unchanged price force RSI 50?
No. Our t5 zero change scales both positive states equally, leaving RSI 66.6667. A wholly flat seed instead gives G = L = 0 and requires a code convention. Pinned C TA-Lib 0.6.4 returns 0; the official MQL4 example returns 50. The currently read main branch also returns 50, so retain exact source version rather than assuming a mutable link defines every result.
Can a stored RSI 50 alone reproduce the next reading?
No. For assigned RSI 3 states G = L = 1, one rise of 1 gives RSI 60. After six flat changes, G = L = 64/729 still gives 50, but the same rise produces about 87.0051. The previous ratio does not retain the absolute state scale. Save G/L and the algorithm, and distinguish display rounding from actual stored-value rounding.
Sources & bibliography
-
Wikipedia Relative strength index · An encyclopaedia overview at the linked URL, rather than the original book text. en.wikipedia.org ↗
-
Investopedia Relative Strength Index (RSI) Indicator Explained · An introductory explanation of RSI and its calculation. www.investopedia.com ↗
-
StockCharts ChartSchool Relative Strength Index (RSI) · An extended explanation of RSI with examples and conventional signal interpretations. chartschool.stockcharts.com ↗
-
Constance Brown Technical Analysis for the Trading Professional · McGraw-Hill, second edition, 2011; the chapter discusses changes in RSI ranges across trends. www.mhprofessional.com ↗
-
TA-Lib — C release0.6.4 RSI source: initialization, recurrence and zero-case handling · Pinned code defines the selected Wilder-style calculation and zero/near-zero convention. A mutable main branch currently differs in zero-total handling. raw.githubusercontent.com ↗
-
MetaQuotes MQL4 Reference — Custom Indicator Properties, RSI example · The official custom-indicator code initializes and updates gains/losses and returns 50 for both-zero states. It does not certify every built-in MetaTrader version. docs.mql4.com ↗
-
TradingView Relative Strength Index (RSI) · The calculation uses gain/loss RMA and declared settings. Threshold and divergence descriptions are separate from evidence of profitable execution. www.tradingview.com ↗
