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.
| Bar | Security | Benchmark | Ratio | 4-bar SMA | MRS |
|---|---|---|---|---|---|
| 1 | 96 | 100 | 0.96 | Not ready | Not ready |
| 2 | 100 | 100 | 1.00 | Not ready | Not ready |
| 3 | 104 | 100 | 1.04 | Not ready | Not ready |
| 4 | 110 | 100 | 1.10 | 1.025 | +0.7317 |
| 5 | 105 | 100 | 1.05 | 1.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.
| Window | What is averaged | Constraint |
|---|---|---|
| 52 on 1W | 52 weekly closing ratios | Weekly convention in the cited source |
| 252 on 1D | 252 daily closing ratios | Approximate trading year for this daily variant |
| 200 on 1D | 200 daily closing ratios | Daily 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.
//@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
- On one closed bar, record both closing prices, timestamps, currencies and the chosen N. Recompute their ratio independently.
- 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.
- 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.
- 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.
- 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 guideSpecify 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 AgentFrequently asked questions
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.