This code is the result of an idea by @MarcoOlivano. The question was that if putting the comparative relative strength as an RSI oscillator would help in understanding the relative strength of the stock to the overall market? As we both trade the JSE I have made the JSE:J200 or Top 40 the basis for comparison. This can be changed in the settings dropdown if you want to compare with the All Share Index (JSE:J201) or other markets such as the S&P.
On the chart above I have included the Comparative Relative Strength as a reference together with the Comparative Relative Strength RSI.
If you use the indicator or adapt it please let me know if it works for you, how you use it and if it has any value.