def BarsUsedForRange = 2; def BarsRequiredToRemainInRange = 7; def HH = Highest(high[1], BarsUsedForRange); def LL = Lowest(low[1], BarsUsedForRange); def maxH = Highest(HH, BarsRequiredToRemainInRange); def maxL = Lowest(LL, BarsRequiredToRemainInRange); def HHn = if maxH == maxH[1] or maxL == maxL then maxH else HHn[1]; def LLn = if maxH == maxH[1] or maxL == maxL then maxL else LLn[1]; def Bh = if high <= HHn and HHn == HHn[1] then HHn else Double.NaN; def Bl = if low >= LLn and LLn == LLn[1] then LLn else Double.NaN; def CountH = if IsNaN(Bh) or IsNaN(Bl) then 2 else CountH[1] + 1; def CountL = if IsNaN(Bh) or IsNaN(Bl) then 2 else CountL[1] + 1; def ExpH = if BarNumber() == 1 then Double.NaN else if CountH[-BarsRequiredToRemainInRange] >= BarsRequiredToRemainInRange then HHn[-BarsRequiredToRemainInRange] else if high <= ExpH[1] then ExpH[1] else Double.NaN; def ExpL = if BarNumber() == 1 then Double.NaN else if CountL[-BarsRequiredToRemainInRange] >= BarsRequiredToRemainInRange then LLn[-BarsRequiredToRemainInRange] else if low >= ExpL[1] then ExpL[1] else Double.NaN; # Plot the High and Low of the Box; Paint Cloud plot BoxHigh = if !IsNaN(ExpL) and !IsNaN(ExpH) then 1 else 0; BoxHigh.AssignValueColor(if BoxHigh > 0 then Color.ORANGE else Color.CURRENT); AssignBackgroundColor(if BoxHigh > 0 then Color.ORANGE else Color.CURRENT);