Rank Correlation Index. The calculation algorithm may not be optimal.
// // @author Jadbrother // //@version=2 study(title = "RCI", shorttitle = "RCI") itv = input(12, "interval") src = input(close, "source") ord(seq, idx, itv) => p = seq[idx] o = 1 for i = 0 to itv - 1 if p < seq[i] o := o + 1 o d(itv) => sum = 0.0 for i = 0 to itv - 1 sum := sum + pow((i + 1) - ord(src, i, itv), 2) sum rci(itv) => (1.0 - 6.0 * d(itv) / (itv * (itv * itv - 1.0))) * 100.0 plot(rci(itv), title = "RCI")
I want to have three RCI lines (9, 26,52) on the same chart.
I tried to make my own script and have been struggling for a while, but couldn't make it.
It would be very grateful if you made the three-period version.