declare upper;
declare once_per_bar;
input Length = 8;
def fH =
if !isnan(close[-Length]) then Double.NaN
else if isnan(close[-Length]) and !isNaN(close[-(Length - 1)])
then GetValue(Highest(high,Length),-(Length - 1))
else fH[1]
;
plot H = fh;
H.setpaintingStrategy(paintingStrategy.HORIZONTAL);
H.setdefaultColor(color.red);
def fL =
if !isnan(close[-Length]) then Double.NaN
else if isnan(close[-Length]) and !isNaN(close[-(Length - 1)])
then GetValue(Lowest(Low,Length),-(Length - 1))
else fL[1]
;
plot L = fL;
L.setpaintingStrategy(paintingStrategy.HORIZONTAL);
L.setdefaultColor(color.green);