Infiten's Return Candle Oscillator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © spiritualhealer117

//@version=4
study("RCO")
len = input(title="Short Length", type=input.integer, defval=14)
long_len = input(title="Long Length", type=input.integer, defval=14)

o_c = (open-open[1])/open[1] + 1
l_c = (low-low[1])/low[1]+ 1
h_c = (high-high[1])/high[1]+ 1
c_c = (close-close[1])/close[1]+ 1


ocprod = 1.0
ccprod = 1.0
lcprod = 1.0
hcprod = 1.0

for i = 0 to len
    ocprod := ocprod * o_c[i]
    lcprod := lcprod * l_c[i]
    hcprod := hcprod * h_c[i]
    ccprod := ccprod * c_c[i]

rco_av = ((ccprod+hcprod+lcprod+ocprod)/4)-1
rco_max_thresh = highest(rco_av,long_len)
rco_min_thresh = lowest(rco_av,long_len)
rco_smoothed = sma(rco_av, long_len)

hline(0)
c = rco_av>0?color.new(color.green,min(75,abs((rco_max_thresh[1]-rco_av)/rco_av)*100)):color.new(color.red,min(75,abs((rco_min_thresh[1]-rco_av)/rco_av)*100))

plot(rco_smoothed, color=c, linewidth=4)


plotcandle(ccprod-1, hcprod-1, lcprod-1, ocprod-1, title = 'RCO', color = ocprod < ccprod ? color.green : color.red, wickcolor= ocprod < ccprod ? color.green : color.red,bordercolor= ocprod < ccprod ? color.green : color.red)
