//@version=5
indicator("Stochastic", shorttitle="Stochastic", overlay = false)
itvs = input(9, 'short interval')
itvm = input(16, 'middle interval')
itvl = input(48, 'long interval')
itvMul = input(9, 'Multi interval')
src5t = input(close, 'source')
resCustom = input.timeframe(title='TimeFrame', defval='240')
res5t = resCustom
ord(seq, idx, itv) =>
p = seq[idx]
o = 1
s = 0
for i = 0 to itv - 1 by 1
if p < seq[i]
o += 1
o
else
if p == seq[i]
s += 1
o + (s - 1) / 2.0
o
d(itv) =>
sum = 0.0
for i = 0 to itv - 1 by 1
sum += math.pow(i + 1 - ord(src5t, i, itv), 2)
sum
sum
rci(itv) =>
(1.0 - 6.0 * d(itv) / (itv * (itv * itv - 1.0))) * 100.0
outRCI = request.security(syminfo.tickerid, res5t, rci(itvMul))
plot(((rci(itvs) + 100)/200)*100, title="RCI short", color=color.yellow, linewidth=2)
plot(((rci(itvm) + 100)/200)*100, title="RCI middle", color=color.red, linewidth =4)
plot(((rci(itvl) + 100)/200)*100, title="RCI long", color=color.blue, linewidth =5)
plot(((outRCI + 100)/200)*100, title="RCI S1", linewidth=3, color=#FFFFFF)