Indicator · Pine Script v6 · Own pane

Mansfield Relative Strength indicator

by etnt

This indicator calculates Mansfield Relative Strength by comparing the current asset's close against a reference index, sector, or industry benchmark.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code47
Settings8inputs
LicenceMPL-2.0
Last update1 year ago3 Aug 2025

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

47 lines of Pine Script v6 from PineScript/mansfield-relative-strength.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

mansfield-relative-strength.pine
//@version=6

// Use this indicator to compare how security is performing in compare with prefered index (SPX by default). 
// > 0 outperforming 
// < 0 underperforming
// Works best for weekly, but can be applied to monthly and daily charts. It will be rather useless to use it in smaller timeframes
// Apply it to SPX, industry index, sector index or other security in similar sector

// UPDATE 1: Added sector and industry as optional params. Leave them same as index if you don't want to use them

indicator("Mansfield Relative Strength indicator", overlay=false)

index = input.symbol(title="Index", defval="SP:SPX")
sector = input.symbol(title="Sector (optional)", defval="SP:SPX")
industry = input.symbol(title="Industry (optional)", defval="SP:SPX")

ma_type = input.string(title="Which moving average to use?", defval="WMA", options=["SMA", "WMA", "EMA"])
len_daily = input(title="MA length for Daily", defval=200)
len_weekly = input(title="MA length for Weekly", defval=52)
len_monthly = input(title="MA length for Monthly", defval=10)
len_other = input(title="MA length for all other periods", defval=52)
val = close

period = timeframe.period
len = period == "W" ? len_weekly : (period == "D" ? len_daily : (period == "M" ? len_monthly : len_other))

ma_func(x, length) =>
    ma_type == "WMA" ? ta.wma(x, length) : (ma_type == "SMA" ? ta.sma(x, length) : ta.ema(x, length))

  
calc_mrs_func(x, ind, length) =>
    security = request.security(ind, period, x)
    ((x / security) / ma_func((x / security), length) - 1) * 10


mrs_index = calc_mrs_func(val, index, len)
mrs_sector = calc_mrs_func(val, sector, len)
mrs_industry = calc_mrs_func(val, industry, len)
c = math.sign(mrs_index) + math.sign(mrs_sector) + math.sign(mrs_industry)

//bgcolor(c == 3 ? color.new(color.green, 80) : c == 2 ? color.new(color.green, 75) : c == 1 ? color.new(color.green, 70) : c == -1 ? color.new(color.red, 70) : c == -2 ? color.new(color.red, 75) : c == -3 ? color.new(color.red, 80) : color.gray)
p_mrs = plot(mrs_index, color=color.white, linewidth=1, title="MRS index")
p_ema = plot(ta.ema(mrs_index,len / 2), title="EMA of MRS index", linewidth=1, color=color.blue)
fill(p_mrs, p_ema, color=mrs_index > ta.ema(mrs_index,len / 2) ? color.new(color.yellow, 80) : na, title="Fill when MRS > EMA")
//plot(mrs_sector != mrs_index ? mrs_sector : na, linewidth=1, title="MRS sector")
//plot(mrs_industry != mrs_index ? mrs_industry : na, linewidth=1, title="MRS industry")
//hline(price=0, color=color.white, linestyle=hline.style_dashed, title="Zero baseline")

Overview

Mansfield Relative Strength indicator plots the resulting relative strength curve alongside an exponential moving average in a separate pane, highlighting when the indicator trades above its moving average. Positive values denote outperformance relative to the benchmark, whereas negative values reflect underperformance. Users can customize benchmark symbols, choose between SMA, WMA, or EMA smoothing, and set period lengths across daily, weekly, and monthly charts. It generates comparison data without execution rules.

Details

Published by

etnt on GitHub

Draws

Separate pane below the 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
IndexsymbolSP:SPXindex
Sector (optional)symbolSP:SPXsector
Industry (optional)symbolSP:SPXindustry
Which moving average to use?stringWMAma_type
MA length for Dailyint200len_daily
MA length for Weeklyint52len_weekly
MA length for Monthlyint10len_monthly
MA length for all other periodsint52len_other
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

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop
228 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator
99 stars

Calculates the Archer Moving Averages Trends (AMAT) indicator by comparing fast and slow Exponential Moving Averages (EMAs) alongside their slope directions. A bullish trend (+1) is identified when the fast EMA exceeds the slow EMA with both rising, while a be

Indicator v6 TrendMoving averages
Updated 4 weeks ago · Apache-2.0 GitHub repository of Archer Moving Averages Trends (AMAT)

Colored fill

by be-thomas
65 stars

This indicator plots two simple moving averages of close, one over five bars and one over twenty bars, in a separate pane. It shades the area between the two plots green when the shorter average is above the longer average and red when it is below. There are n

Indicator v4 Moving averagesTrend
Updated 6 days ago · GPL-3.0 GitHub repository of Colored fill

More Trend 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