TradingView indicator calculations

Relative Momentum Index: momentum length versus RSI

The Relative Momentum Index (RMI) applies an RSI-style gain/loss ratio to changes across M bars instead of changes across one bar. M controls the momentum span; N controls the smoothing of those changes. With M = 1 and identical source, smoothing, initialization, and zero handling, RMI reduces to RSI. Changing M changes the measured price move, not just the smoothness of an existing RSI line.

See the decision guide

Two lengths control different parts of the calculation

For bar t, calculate delta = close[t] − close[t−M], U = max(delta, 0), and D = max(−delta, 0). Smooth U and D separately over N observations, then calculate RMI = 100 × Uavg / (Uavg + Davg). These are price-change magnitudes, not counts of rising and falling bars. Roger Altman introduced RMI as a modification of RSI; the published TradingView implementation by everget also identifies M = 1 as the RSI comparison case.

  • Here, Wilder smoothing uses alpha = 1/N. Seed each average with the arithmetic mean of its first N valid changes; afterwards, average[t] = ((N − 1) × average[t−1] + current change) / N.
  • For consecutive valid prices, the first RMI value can appear on bar M + N, counting the first price as bar 1. RSI with M = 1 can appear on bar N + 1. Do not fill earlier missing changes with zeros.
  • Smoothing type is part of the definition. Sierra Chart exposes several moving-average types and its own initialization and flat-data policy. An SMA or EMA variant need not match the Wilder version below.
SettingWhat it changesWhat it does not mean
M: momentum spanThe distance between the two compared closesAn extra moving average of RSI
N: smoothing lengthThe averaging of positive and negative M-bar changesThe distance between those closes
Chart timeframeThe duration represented by each barM daily bars when the chart is intraday

Compare RMI and RSI on one price sequence

Use these hypothetical closes, in order: 100, 102, 101, 104, 103, 102, 101, 100, 102, 104, 103. Set N = 3 for both calculations and M = 2 for RMI. There is no earlier history in this fixture. RSI uses one-bar changes; both averages use the seed and Wilder recurrence above. Displayed results are rounded to two decimals only after calculation.

  • At bar 5, the first three RMI changes are 1, 2, 2. Uavg = 5/3 and Davg = 0, so RMI = 100. The latest close fell from 104 to 103, yet it remains above the close two bars earlier.
  • At bar 6, Uavg = (2 × 5/3 + 0)/3 = 10/9; Davg = (2 × 0 + 2)/3 = 2/3. RMI = 100 × (10/9)/(16/9) = 62.50.
  • RSI crosses above 50 at bar 9; RMI crosses above 50 at bar 10. This sequence demonstrates different timing, not a rule that RMI always crosses one bar later.
  • At bar 11, RMI rises to 78.43 while RSI falls to 58.67. The two-bar change is still positive. A higher RMI does not require a higher close than the immediately preceding bar.
BarCloseOne-bar changeTwo-bar changeRSI (N = 3)RMI (N = 3, M = 2)
1100MissingMissingWarming upWarming up
21022MissingWarming upWarming up
3101−11Warming upWarming up
41043283.33Warming up
5103−1266.67100.00
6102−1−251.2862.50
7101−1−238.1040.00
8100−1−227.4925.97
91022160.4941.39
101042476.5273.94
11103−1158.6778.43

Resolve zero denominators and persistent extremes

Use the total Uavg + Davg as the denominator. If it is positive, an absence of losses gives 100 and an absence of gains gives 0. If both averages are zero, there is no directional movement to normalize. This page returns na for that case instead of assigning a trading interpretation to 0/0.

  • With closes 100, 101, 102, 103, 104, 105 and M = 2, N = 3, RMI is 100 on bars 5 and 6. Continued positive two-bar changes can keep it there. An upper-zone reading does not set a reversal deadline.
  • A constant sequence from the start gives zero averages and na. Flat prices following earlier movement behave differently: Wilder averages retain decaying history. Once the M-bar changes become zero, both averages decay by the same factor, so their ratio can remain unchanged.
  • Other scripts may carry forward the prior value or substitute 50 when the denominator is zero. Match that policy before interpreting a disagreement as an error.
ConditionResult in this exampleConsequence
Uavg > 0; Davg = 0100Valid upper extreme, not a division error
Uavg = 0; Davg > 00Valid lower extreme
Uavg = Davg > 050Balanced smoothed magnitudes
Uavg = Davg = 0naNo ratio and no crossing alert
Insufficient valid historynaWait for the seed observations

Separate threshold states from confirmed crossings

For an upward crossing of 50, the current value must be greater than 50 and the previous value must be at or below 50. Both must be valid. Equality on the current bar is not a crossing. A bar above 70 is a state; an entry above 70 and a return below 70 are separate events. Choose the event before creating an alert.

  • In the fixture, both lines enter above 70 on bar 10. On bar 11, only RSI returns below 70; RMI remains above it. Counting every upper-zone bar as a new entry would count a different signal.
  • The first valid RMI value at bar 5 is 100, but its predecessor is missing. The example does not treat this warm-up completion as a crossing.
  • The live close can move across a threshold and return before the candle finishes. The script gates plots and alert conditions with barstate.isconfirmed; set alerts to Once Per Bar Close as well.
  • Changing script inputs does not update an already running alert snapshot. Recreate the alert after changing the span, smoothing length, symbol, or timeframe.

Audit the Wilder version in Pine Script v6

Paste this indicator into TradingView and use a standard candle chart. Defaults N = 3 and M = 2 match the arithmetic example, not a recommended trading setup. The Data Window exposes each smoothed component. The table above is a synthetic fixture; arbitrary market candles will not reproduce those values.

  • Set M to 1 and compare with the RSI plot after warm-up on data with nonzero total movement. Investigate source, history, and flat-data policies before expecting equality everywhere.
  • Use the same symbol, exchange feed, timeframe, session, candle type, and loaded history when comparing scripts. Recursive smoothing can retain differences from an earlier seed.
  • Record the Data Window value and timestamp at a completed bar. Passing a syntax check confirms compilation, not agreement with every community RMI variant or trading profitability.
Wilder-smoothed RMI with explicit zero handling and chart-timeframe confirmation. This indicator declares alert conditions; it does not place orders.pine
//@version=6
indicator("RMI and RSI calculation audit", overlay = false, precision = 2)
length = input.int(3, "Wilder smoothing length N", minval = 1)
span = input.int(2, "Momentum span M", minval = 1)
changeM = close - close[span]
upAverage = ta.rma(math.max(changeM, 0.0), length)
downAverage = ta.rma(math.max(-changeM, 0.0), length)
total = upAverage + downAverage
rmi = not na(total) and total > 0 ? 100.0 * upAverage / total : na
rsi = ta.rsi(close, length)
crossAbove50 = ta.crossover(rmi, 50.0)
crossBelow70 = ta.crossunder(rmi, 70.0)
validPair = not na(rmi) and not na(rmi[1])
confirmed = barstate.isconfirmed
plot(confirmed ? rmi : na, "RMI", color = color.blue, linewidth = 2, style = plot.style_linebr)
plot(confirmed ? rsi : na, "RSI", color = color.orange, style = plot.style_linebr)
hline(70, "Upper reference", color = color.gray)
hline(50, "Midpoint", color = color.gray)
hline(30, "Lower reference", color = color.gray)
plot(confirmed ? upAverage : na, "Smoothed M-bar gains", display = display.data_window)
plot(confirmed ? downAverage : na, "Smoothed M-bar losses", display = display.data_window)
alertcondition(confirmed and validPair and crossAbove50, "RMI crosses above 50", "Confirmed RMI crossed above 50.")
alertcondition(confirmed and validPair and crossBelow70, "RMI crosses below 70", "Confirmed RMI crossed below 70.")

Turn the verified definition into an editable rule

The Pine Script AI Coding Agent can help draft or revise an RMI indicator from the public calculation. Specify the source, separate M and N inputs, Wilder seed, na policy, and confirmed crossing condition. Keep the diagnostic averages in the output so the result remains inspectable.

  • Compare generated values in TradingView before adding alerts or strategy orders. Ask for an explanation when a value or crossing differs from the fixture.
  • The public formula does not reveal a protected indicator's private filters. Do not assume a generated RMI reproduces proprietary source code.
  • A trading strategy still needs explicit exits, sizing, costs, and independent evaluation. This calculation example supplies no evidence of an edge.
Where Pineify fits

Pine Script AI Coding Agent

Draft an RMI rule with separate momentum and smoothing inputs, inspect the source, and compare its confirmed values in TradingView.

Draft an RMI rule

Frequently asked questions

Educational information, not investment advice. Prices are hypothetical calculation fixtures, not backtest or live trading results. Oscillator thresholds and valid syntax do not establish profitability.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.