plot Data = close; declare lower; declare once_per_bar; def nan = Double.NaN; def agg = AggregationPeriod.DAY; def vhigh = high(period = agg); def v1 = vhigh from 17 bars ago; def v0 = vhigh from 16 bars ago; # show the high values of the bars (correct values displayed AddLabel(1, " v1 " + v1, Color.GREEN); AddLabel(1, " v0 " + v0, Color.GREEN); def condition = v1 > v0; def highUpCount = CompoundValue(1, if condition then highUpCount[1] + 1 else highUpCount[1] , 0); AddLabel(1, "HiCnt " + highUpCount, Color.GREEN); TimeĀ  High condition v1>v0 Count 2/6/2020 230.04 1 2/5/2020 229.65 1 2/4/2020 228.63 1 2/3/2020 225.75 0 1/31/2020 227.71 1 1/30/2020 219.85 1 1/29/2020 218.44 1 6 1/28/2020 217.72 1 1/27/2020 213.22 0 1/24/2020 214.84 1 8 1/23/2020 213.29 1 1/22/2020 212.83 1 1/21/2020 212.28 1 1/17/2020 211.96 1 1/16/2020 210.98 1 1/15/2020 210.32 1 14 1/14/2020 209.24 0 1/13/2020 209.46 0 1/10/2020 209.83 1 1/9/2020 209.54 1 16 1/8/2020 209.1 1 1/7/2020 208.51 0 1/6/2020 208.57 0 1/3/2020 208.91 0 1/2/2020 209.88 1 12/31/2019 208.41 1 12/30/2019 208.36 0 12/27/2019 208.36 0 12/26/2019 208.05 1 12/24/2019 207.78 0 20 12/23/2019 210.82 1