One Year Return
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © lucasschnare1

//@version=4
study("One yr return")

hi = input(false, "Average Return above 0")
lo = input(false, "Average Return below 0")

return1 = (((close - close[50]) / close[50] ) *100 )

color1 = return1 >= 0 ? color.blue : color.yellow

plot(0, color = color1)


re = cum(return1) / bar_index

rere = bar_index


count1 = return1 < 0 ? 1 : 0
count2 = return1 > 0 ? 1 : 0

total1 = cum(count1)
total2 = cum(count2)
    

lowavg = return1 < 0 ? return1 : 0
highavg = return1 > 0 ? return1 : 0


t1 = cum(lowavg) / total1
t2 = cum(highavg) / total2


color2 = color.new(color.green, transp = 100)
color3 = color.new(color.red, transp = 100)



y1 = plot(lo ? t1 : na, color = color3)
y2 = plot(hi ? t2 : na, color = color2)

fill(y1, y2, color = color.blue)


plot(return1, color = color1)
