cowen risk index
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OrionAlgo

//@version=5
indicator("cowen risk index", overlay=false, max_bars_back = 4999)


maLen = input.int(400)
increaseMABool = input.bool(false, "Increase MA until Length is met")
factorBool = input.bool(false, "Custom Factor")
factor = input.float(1.00042)


var bar = 1.
bar:= timeframe.period == "D" ? factorBool? bar*factor: bar*1.00042 : timeframe.period == "W" ? factorBool? bar*factor: bar*1.002 : 0
count = ta.cum(1+1==2 ? 1 : 0)
ma = increaseMABool? ta.sma( close, count<maLen?math.round(count):maLen) : ta.sma(close,maLen)

calc = (request.security(syminfo.tickerid, "D",(close/ma)))*bar 

signal = calc

plot(signal,color=color.rgb(255,255,255,50))

var top = 0.
if (signal>=top[1]) 
    top := signal

plot(0,color=color.rgb(0,255,0,50))
plot(top*0.1,color=color.rgb(0,255,0,60))
plot(top*0.2,color=color.rgb(0,255,0,70))
plot(top*0.3,color=color.rgb(0,255,0,80))
plot(top*0.4,color=color.rgb(0,255,0,90))
plot(top*0.5,color=color.rgb(255,255,255,90))
plot(top*0.6,color=color.rgb(255,0,0,90))
plot(top*0.7,color=color.rgb(255,0,0,80))
plot(top*0.8,color=color.rgb(255,0,0,70))
plot(top*0.9,color=color.rgb(255,0,0,60))
plot(top,color=color.rgb(255,0,0,50))

