Mansfield RS
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © franmor01981

// **** Standard Relative Performance indicator
//The formula for calculating standard relative performance indicator is quite simple:
//Code:
//RP = ( stock_close / index_close ) * 100

// **** Mansfield Relative Performance indicator
//The formula of this indicator is a bit more difficult than the regular Standard Relative Performance indicator:
//MRP = (( RP(today) / sma(RP(today), n)) - 1 ) * 100
//Where:
//RP = Standard Relative Performance indicator (see above)
//SMA = Simple moving average over n days.
//n = 52 for weekly charts, and n = 200 on daily charts



//@version=5
indicator("Mansfield RS")


// Retrieve the other symbol's data
sym = input.symbol(title="Symbol", defval="SP:SPX")
spx = request.security(sym, input.timeframe('W', "Resolution", options=['D', 'W', 'M']), close, gaps= barmerge.gaps_on)


RP = ( close / spx ) * 100
RP52W = ta.sma(RP,52)
MRP = (( RP / RP52W) - 1 ) * 10

color plotColor = color.white

if (MRP >= 0.0)
    plotColor := color.green
else if (MRP < 0.0)
    plotColor := color.red

plot(MRP, title= 'MA(52)', style=plot.style_area, color=plotColor)