Indicator · Pine Script v6 · On the chart

Mansfield RS Weekly Crossovers

by major

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.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code73
Settings7inputs
LicenceApache-2.0
Last update3 weeks ago30 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

73 lines of Pine Script v6 from mansfield_relative_strength/mansfield_relative_strength_overlay.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

mansfield_relative_strength_overlay.pine
// 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.

Details

Published by

major on GitHub

Draws

On the price chart

Markets

Stocks, Indices

Timeframes

H4 and above

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
BenchmarksymbolSP:SPXbenchmark
Reset Distance Below Zerofloat1.0resetMagnitude
Cooldown Weeksint2cooldownWeeks
Show MarkersbooltrueshowMarkers
Marker Colorcolorcolor.limemarkerColor
Show RS TextbooltrueshowRSText
Text Colorcolorcolor.limersTextColor
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.

Similar Pine Scripts

947 stars

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

Indicator v4 Moving averagesOscillators & momentum
Updated 5 weeks ago · GPL-3.0 GitHub repository of Adaptive RSI Moving Average
228 stars

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

Indicator v6 Screeners & dashboardsTrend
Updated 4 months ago · None stated GitHub repository of TradersPost Trading Checklist

Daily Trend Filter

by agutinbaigo28
147 stars

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

Indicator v5 TrendOscillators & momentum
Updated 2 months ago · MIT GitHub repository of Daily Trend Filter

AAPP

by capissimo
114 stars

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

Indicator v4 Moving averagesTrend
Updated 2 years ago · None stated GitHub repository of AAPP

Signal Strategy 15m

by tripolskypetr
72 stars

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

Indicator v5 TrendMoving averages
Updated 4 weeks ago · MIT GitHub repository of Signal Strategy 15m
57 stars

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

Indicator v5 TrendMoving averages Repaints
Updated 4 months ago · None stated GitHub repository of Double Screened Decision

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers