Cycles
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © csmottola71

//@version=4
study("Cycles")
cycle=input(title="Cycle Days", type=input.integer, step=1, defval=55)
l = lowest(low,cycle)
lSince = barssince(l < l[1])
h = highest(high,cycle)
hSince = barssince(h > h[1])
linea=0-(hSince-lSince)
bgCol = linea > linea[1] ? color.green : linea < linea[1] ? color.yellow : color.white 
bgcolor(color.new(bgCol,65))
//plot(lSince, color=color.red)
//plot(hSince, color=color.blue)
plot(linea, color= linea > 0 ? color.blue : color.red)

