ITMScript
Measure relative strength against SPY
Divide the close by the close of SPY to see whether a symbol is gaining on it, with an average to read the trend.
Divide the close by the close of SPY, and compare the result with its own average.
//@itmscript 2
study("Relative strength", overlay=false)
len = input.int(50, "Average length", min=2, max=500)
bench = series(symbol="SPY")
ratio = close / bench.close
avg = ta.sma(ratio, len)
plot(ratio, "Close over SPY", color=ratio > avg ? color.green : color.red, width=2, style=line)
plot(avg, "Average", color=color.gray, width=1, style=line)What you see
The ratio is drawn in its own pane. It is green while it is above its average and red while it is below. A rising ratio means the symbol is gaining on SPY. A grey line shows the average.
Where SPY has no bar, the ratio is missing and the line has a gap. A study that reads another symbol needs those bars to be loaded. Other symbols and timeframes explains when each value is visible.
Change these inputs
- Average length. The window of the average of the ratio, from 2 to 500 bars.
The benchmark is written in the script. Replace SPY in the series line with another symbol to compare against that one.