TradingView indicator guides

Mansfield Relative Strength on TradingView: formula and limits

The Mansfield Relative Strength indicator divides a security's price by a benchmark, then compares that ratio with its own moving average. A positive reading means the ratio is above its average. It is a measure of relative price strength, not RSI, a return forecast or proof that the security is rising.

Calculation used on this page

ratio = security close / benchmark close
MRS = 10 × (ratio / SMA(ratio, N) − 1)

52 weekly observations by default. The daily variant uses 252 daily observations. The code exposes the ratio and its SMA in the Data Window.

The ratio, its average and the zero line

Let R be the security close divided by the benchmark close, and A be the mean of the latest N ratios, including the current observation. Mansfield RS is 10 × (R/A − 1) in this example. R = A gives zero. R = 1.1A gives +1.0, which means a 10% deviation above the ratio average.

The Stage Analysis calculation uses the same normalization with a multiplier of 100. Scaling by 10 instead changes only the displayed units. Do not copy numerical thresholds between these versions without converting them.

A positive level and a rising ratio answer different questions. A ratio can fall from 1.12 to 1.10 and remain above an average of 1.00. Its relative position is still positive, but it lost ground on the latest bar. Likewise, a zero crossing does not measure the difference between two trailing annual returns.

A worked example you can reproduce

These are invented aligned closing prices in the same currency. The four-observation window is deliberately short so every input is visible; it is not a suggested trading setting. The benchmark stays at 100.

Hypothetical calculation, N = 4 and multiplier = 10
BarSecurityBenchmarkRatio4-bar SMAMRS
1961000.96Not readyNot ready
21001001.00Not readyNot ready
31041001.04Not readyNot ready
41101001.101.025+0.7317
51051001.051.0475+0.0239

At bar 4, A = (0.96 + 1.00 + 1.04 + 1.10)/4 = 1.025. MRS = 10 × (1.10/1.025 − 1) = 0.7317. At bar 5, the oldest ratio drops out. The stock falls from 110 to 105, yet MRS stays slightly positive because 1.05 remains above 1.0475.

The four ratios determine this MRS value. They do not determine a standard RSI(14), which requires the security's gain/loss history and smoothing state. No benchmark belongs in the RSI calculation.

Choose a benchmark and a sampling convention

The benchmark defines the comparison: a broad market index, a sector series or a peer security answers a different question. Record its full exchange-qualified symbol. SP:SPX is the example default, not a mandatory part of the formula. The Stage Analysis setup guide describes changing that comparison symbol.

WindowWhat is averagedConstraint
52 on 1W52 weekly closing ratiosWeekly convention in the cited source
252 on 1D252 daily closing ratiosApproximate trading year for this daily variant
200 on 1D200 daily closing ratiosDaily example in the cited source

A daily average weights every daily close; a weekly average samples weekly closes. Changing 52 to 252 does not make their outputs identical. Holidays, missing sessions and 24/7 markets also change the calendar span. This script deliberately rejects intraday, monthly and multi-day charts instead of silently assigning an unrelated length.

Keep the price basis consistent too. Dividend-adjusted equity prices against a price-only index do not represent an equal total-return comparison. Split handling, sessions and synthetic candles can alter the ratio. The example accepts standard charts; verify feed and adjustment settings before comparing values from another platform.

Pine Script v6 with explicit data boundaries

Copy the code into TradingView's Pine Editor, save it and add it to a standard 1W or 1D chart. Set the benchmark and lengths in Inputs. The example plots confirmed chart bars and uses the chart timeframe for both price series.

Pine Script v6

//@version=6
indicator("Mansfield RS - aligned closes", overlay = false, precision = 4)

benchmarkSymbol = input.symbol("SP:SPX", "Benchmark")
weeklyLength = input.int(52, "Weekly SMA length", minval = 2)
dailyLength = input.int(252, "Daily SMA length", minval = 2)
isWeekly = timeframe.isweekly and timeframe.multiplier == 1
isDaily = timeframe.isdaily and timeframe.multiplier == 1
if not (isWeekly or isDaily) or not chart.is_standard
    runtime.error("Use a standard 1W or 1D chart.")
length = isWeekly ? weeklyLength : dailyLength

[benchmarkClose, benchmarkEnd, benchmarkCurrency] = request.security(benchmarkSymbol, timeframe.period, [close, time_close, syminfo.currency], gaps = barmerge.gaps_on, lookahead = barmerge.lookahead_off, ignore_invalid_symbol = true)
aligned = not na(benchmarkClose) and benchmarkClose > 0 and not na(close) and close > 0 and benchmarkEnd == time_close and benchmarkCurrency == syminfo.currency
ratio = aligned ? close / benchmarkClose : na
var int consecutiveValid = 0
consecutiveValid := aligned ? consecutiveValid + 1 : 0
ratioAverage = ta.sma(ratio, length)
ready = consecutiveValid >= length and not na(ratioAverage) and ratioAverage > 0
mrs = ready ? 10.0 * (ratio / ratioAverage - 1.0) : na
confirmedMrs = barstate.isconfirmed ? mrs : na

plot(confirmedMrs, "Mansfield RS (x10)", color = color.blue, linewidth = 2, style = plot.style_linebr)
hline(0, "Ratio equals its SMA", color = color.gray, linestyle = hline.style_dashed)
bgcolor(na(confirmedMrs) ? na : confirmedMrs > 0 ? color.new(color.green, 90) : confirmedMrs < 0 ? color.new(color.red, 90) : na)
plot(ratio, "Raw ratio", display = display.data_window)
plot(ratioAverage, "Ratio SMA", display = display.data_window)
plot(consecutiveValid, "Consecutive valid pairs", display = display.data_window)

The script uses gaps_on and lookahead_off. Missing benchmark prices produce gaps. It also requires equal currency codes and close timestamps, then waits for a complete consecutive window after any invalid pair. This is an intentionally strict comparison policy, so some cross-market pairs will remain blank.

Currency normalization is a separate decision. A constant currency scale cancels out of R/SMA(R); changing exchange rates do not. This example performs no FX conversion. For a cross-currency comparison, specify a common valuation currency and conversion timing before changing the code. TradingView documents its request currency and gap behavior.

Using the chart's confirmation flag cannot synchronize two exchanges by itself. Equal closing timestamps reduce that ambiguity here, but data vendors can still revise observations. If you adapt the script to request weekly data on a daily chart, use a documented confirmed higher-timeframe pattern; an unoffset lookahead_on request can expose future weekly values in history. See TradingView's higher-timeframe guidance.

Verify values before adding trading rules

  1. On one closed bar, record both closing prices, timestamps, currencies and the chosen N. Recompute their ratio independently.
  2. Inspect Raw ratio, Ratio SMA and Consecutive valid pairs in the Data Window. Recalculate the mean from the last N aligned pairs and compare the final scaled value.
  3. Check a missing-data interval. A zero or absent benchmark must produce no value. The example resets its readiness count; it does not substitute zero or carry forward a stale benchmark.
  4. Check a live bar and reload after it closes. The final MRS line is hidden while the chart bar is open; the diagnostic Data Window values can still develop.
  5. Compare scripts only after matching benchmark, period, length, multiplier and gap policy. With identical feeds, sessions and adjustments, using the chart symbol as its own benchmark should yield zero after warm-up.

A syntax check confirms that code compiles, not that a data feed matches the intended comparison. A trading strategy still needs entry and exit rules, position sizing, fees, slippage and a separate performance evaluation. Mansfield RS alone specifies none of these.

Mansfield RS and RSI answer different questions

TradingView's RSI definition compares smoothed gains with smoothed losses in one price series, on a scale from 0 to 100. Mansfield RS compares two price series and centers their normalized ratio on zero. RSI's 70 and 30 reference levels have no role in this formula.

If a stock falls 5% while its benchmark falls 10%, its raw ratio rises by about 5.56%. That interval shows relative improvement despite an absolute loss. A Mansfield reading still depends on its rolling average, while RSI depends on the stock's own prior moves. Neither reading supplies an automatic buy or sell decision.

Read the RSI Pine Script guide

Specify the comparison in Pineify

Use the Pine Script AI Coding Agent to turn a comparison rule into code you can inspect. Include the benchmark, chart timeframe, length, currency policy, gap handling, output scale and confirmation timing in the request.

Create a Mansfield RS indicator for standard weekly charts using SP:SPX, a 52-observation SMA of aligned closing-price ratios and multiplier 10. Reject currency mismatches and missing or zero prices. Show confirmed values plus the raw ratio and SMA in the Data Window. Explain any missing output before adding strategy logic.

Compare generated values bar by bar first. Define exits and trading costs separately if you later convert the indicator to a strategy.

Open Pine Script AI Coding Agent

Frequently asked questions

Mansfield RS measures the current security/benchmark price ratio relative to the moving average of that ratio. Above zero means the ratio is above its average; it does not prove a positive stock return or a positive return difference over a particular holding period.

No. Mansfield RS needs a benchmark price series. RSI compares smoothed gains and losses within one price series and has a 0 to 100 scale. Its 70/30 reference levels do not apply to Mansfield RS.

Use 52 on a weekly chart for the weekly convention. A 252-bar daily SMA is a separate daily approximation to a trading year. It averages daily observations, so it cannot reproduce a 52-week SMA. The cited Stage Analysis calculation uses 200 for its daily example; record the convention of any script you compare.

Check the output multiplier. With a ratio 10% above its SMA, multiplying the normalized deviation by 10 gives 1; multiplying by 100 gives 10. Zero crossings are unchanged. Also compare benchmark, timeframe, source prices, length and gap policy.

The example only accepts standard 1D or 1W charts. It needs a full consecutive window of valid positive price pairs, matching currency codes and matching close timestamps. Missing benchmark data resets the window. The open chart bar is hidden until it closes.

Yes. In a hypothetical interval, a stock falling from 100 to 95 while its benchmark falls from 100 to 90 raises their ratio from 1 to about 1.0556. Whether Mansfield RS is positive still depends on the ratio average.

Sources and related guides

Sources checked on October 17, 2026. The calculation table is an original hypothetical example. This page explains indicator mechanics and is not investment advice.

Browse TradingView indicator guides