The Mansfield RS Weekly Crossovers indicator measures a security's performance relative to a benchmark index, such as the S&P 500, using the 52-week Mansfield Relative Strength calculation.
// Copyright 2026 Major Hayden
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//@version=6
indicator('Mansfield RS Weekly Crossovers', shorttitle = 'MRS Cross', overlay = true, precision = 2)
benchmark = input.symbol('SP:SPX', 'Benchmark', tooltip = 'Price-relative comparison. Use a benchmark with weekly sessions aligned to the chart symbol, such as SPX for US stocks.')
resetMagnitude = input.float(1.0, 'Reset Distance Below Zero', minval = 0.0, step = 0.1, tooltip = 'Mansfield RS points below zero required to allow another signal. At 1.0, RS must close strictly below -1.0 after a signal. Larger values suppress more repeat crossings.')
cooldownWeeks = input.int(2, 'Cooldown Weeks', minval = 0, tooltip = 'After a signal, suppress new signals for the next N weekly bars. A fresh eligible crossover is required afterward. 0 disables the cooldown but keeps the reset-depth rule.')
showMarkers = input.bool(true, 'Show Markers', group = 'Display', inline = 'markers', tooltip = 'Show or hide crossover markers and their text. This does not change signal calculations or alerts.')
markerColor = input.color(color.lime, 'Marker Color', group = 'Display', inline = 'markers')
showRSText = input.bool(true, 'Show RS Text', group = 'Display', inline = 'text')
rsTextColor = input.color(color.lime, 'Text Color', group = 'Display', inline = 'text')
// A weekly chart keeps the ratio and its SMA in the same 52-week context.
// Synthetic candles and other intervals would change the intended calculation.
if not chart.is_standard or not timeframe.isweekly or timeframe.multiplier != 1
runtime.error('Use a standard 1W chart for Mansfield RS Weekly Crossovers.')
// Enforce regular-session, split-adjusted prices on both legs, independent of
// the chart's dividend-adjustment setting. This is not a total-return measure.
stockTicker = ticker.modify(ticker.standard(syminfo.tickerid), session = session.regular, adjustment = adjustment.splits)
benchmarkTicker = ticker.modify(benchmark, session = session.regular, adjustment = adjustment.splits)
stockClose = request.security(stockTicker, timeframe.period, close, gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_off)
benchmarkClose = request.security(benchmarkTicker, timeframe.period, close, gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_off)
// Mansfield RS = 100 * (ratio / SMA(ratio, 52) - 1).
// Multiplying the raw ratio by 100 is optional: it cancels in normalization.
relativePerformance = not na(stockClose) and stockClose > 0 and not na(benchmarkClose) and benchmarkClose > 0 ? stockClose / benchmarkClose : na
rpMovingAverage = ta.sma(relativePerformance, 52)
mansfieldRS = not na(rpMovingAverage) and rpMovingAverage > 0 ? 100.0 * (relativePerformance / rpMovingAverage - 1.0) : na
// Start eligible, but require two valid RS observations for a real crossing.
// Do not replace missing RS with zero: that would invent startup signals.
var bool armed = true
var int lastSignalBar = na
crossedAbove = ta.crossover(mansfieldRS, 0.0)
hasValidRS = not na(mansfieldRS) and not na(mansfieldRS[1])
validCross = hasValidRS and crossedAbove
// Count from accepted signals only. Block the next N bars, not the first signal.
cooldownReady = na(lastSignalBar) or bar_index - lastSignalBar > cooldownWeeks
signal = barstate.isconfirmed and armed and cooldownReady and validCross
// Commit eligibility changes only at the weekly close. Shallow negative dips
// after a signal do not rearm, and touching the reset level is not sufficient.
if barstate.isconfirmed
if signal
armed := false
lastSignalBar := bar_index
else if not na(mansfieldRS) and mansfieldRS < -resetMagnitude
armed := true
// Inputs own all display controls to avoid duplicate color pickers in Style.
// A missing text color hides the constant RS text without hiding its triangle.
plotshape(signal and showMarkers, title = 'Mansfield RS Zero Cross', style = shape.triangleup, location = location.belowbar, color = markerColor, size = size.tiny, text = 'RS', textcolor = showRSText ? rsTextColor : na, editable = false)
// Keep diagnostic values available without visible or editable chart lines.
// Explicitly hide their colors as well as limiting their display location.
plot(barstate.isconfirmed ? mansfieldRS : na, title = 'Mansfield RS', color = na, editable = false, display = display.data_window, precision = 4)
plot(barstate.isconfirmed and hasValidRS ? (armed and cooldownReady ? 1 : 0) : na, title = 'Ready for Next Crossover', color = na, editable = false, display = display.data_window, precision = 0)
alertcondition(signal, title = 'Mansfield RS Weekly Zero Cross', message = '{{ticker}}: confirmed weekly Mansfield RS crossed above zero after eligibility/reset. RS = {{plot("Mansfield RS")}}.')
Overview
Mansfield RS Weekly Crossovers plots crossover signal markers directly on the price chart when relative performance crosses above zero. To filter out false signals, the indicator enforces configurable reset magnitude rules and a multi-week cooldown period. Users can adjust the benchmark symbol, reset threshold, and cooldown duration. Note that the script requires execution on a standard 1-week chart.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Benchmark
symbol
SP:SPX
benchmark
Reset Distance Below Zero
float
1.0
resetMagnitude
Cooldown Weeks
int
2
cooldownWeeks
Show Markers
bool
true
showMarkers
Marker Color
color
color.lime
markerColor
Show RS Text
bool
true
showRSText
Text Color
color
color.lime
rsTextColor
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
The Adaptive RSI Moving Average (ARSIMA) is an overlay indicator that dynamically adjusts its smoothing factor based on the Relative Strength Index (RSI). When the RSI moves toward extreme overbought or oversold conditions, the smoothing factor increases to ma
TradersPost Trading Checklist is an overlay indicator that evaluates a suite of popular technical conditions for long and short trade setups. It checks session-anchored VWAP, fast and slow EMA alignments and crosses, 200 SMA, RSI overbought or oversold conditi
Calculates market regime conditions by combining RSI, MACD, and ADX/DMI indicators. It evaluates whether the market is in a strong bullish, strong bearish, neutral, or non-trending regime. The script plots a colored line overlaying the close price to reflect t
This indicator plots an adaptive moving average or scaled RSI divergence line directly on the price chart. It calculates dual RSI series to measure momentum divergence, scales the values to the chart's price range, and constructs an adaptive average filtered b
This indicator generates trend-following trade signals on the price chart by combining moving average crossovers with multi-factor filters. It triggers entry alerts when fast and slow EMAs cross in the direction of a baseline trend EMA, confirmed by non-extrem
Double Screened Decision is a multi-timeframe trend and momentum indicator overlaid directly on the price chart. It dynamically selects a higher timeframe based on the active chart resolution to evaluate higher-timeframe MACD, Bollinger Bands, RSI, and Stochas