input sPeriod = {default DAY};
def offset = 1;
def varhigh = high(period = sPeriod)[offset];
def varlow = low(period = sPeriod)[offset];
def h = fold ih = 0 to 1 while !IsNaN(close[10]) do varhigh;
def l = fold il = 0 to 1 while !IsNaN(close[10]) do varlow;
plot DayHigh = if h > 1 then h else Double.NaN;
DayHigh.SetPaintingStrategy(PaintingStrategy.LINE);
DayHigh.SetDefaultColor(Color.LIGHT_GREEN);
plot DayLow = if l > 1 then l else Double.NaN;
DayLow.SetPaintingStrategy(PaintingStrategy.LINE);
DayLow.SetDefaultColor(Color.LIGHT_RED);
AddCloud(if close > DayHigh or close[-1] > DayHigh then DayHigh else Double.NEGATIVE_INFINITY,if close > DayHigh or close[-1] > DayHigh then DayLow else Double.NEGATIVE_INFINITY,color.LIGHT_GREEN,color.LIGHT_GREEN,no);
AddCloud(if close < DayLow or close[-1] < DayLow then DayHigh else Double.NEGATIVE_INFINITY,if close < DayLow or close[-1] < DayLow then DayLow else Double.NEGATIVE_INFINITY,color.LIGHT_RED,color.LIGHT_RED,no);
AddCloud(if (close <= DayHigh and close >= DayLow) or (close[-1] <= DayHigh and close[-1] >= DayLow) then DayHigh else Double.NEGATIVE_INFINITY,if (close <= DayHigh and close >= DayLow) or (close[-1] <= DayHigh and close[-1] >= DayLow) then DayLow else Double.NEGATIVE_INFINITY,color.LIGHT_GRAY,color.LIGHT_GRAY,no);