Cumulative Relative Strength Index
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @version=4
// Author = TradeAutomation

study(title="Cumulative Relative Strength Index", shorttitle="CRSI", format=format.price, precision=2, resolution="")

src = input(close, "Source", type = input.source)
len = input(2, minval=1, title="RSI Length")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

CumulationLength = input(2, "Cumulation Length")
CumulativeRSI = sum(rsi, CumulationLength)

plot(CumulativeRSI, "Cumulative RSI", color=color.purple)
upperhline = hline(100*CumulationLength*input(80, "Upper Line %")*.01)
lowerhline = hline(100*CumulationLength*input(20, "Lower Line %")*.01)
fill(upperhline, lowerhline, color=color.new(color.gray, 80) , title="Background")