Is there better way to find out Higher Highs

I have a scenario here. In a given 30 candles I need to find out how many of them are Higher Highs. I have coded like shown below. So HIGHER_HIGHS variable may have 15 higher highs out of 30 candles. Is there a better way to achieve this?

HIGHER_HIGHS = (H > Ref(H, -1)) + (Ref(H, -1) > Ref(H, -2)) + (Ref(H, -2) > Ref(H, -3)) +
					  (Ref(H, -3) > Ref(H, -4)) + (Ref(H, -4) > Ref(H, -5)) + (Ref(H, -5) > Ref(H, -6)) +
					  (Ref(H, -6) > Ref(H, -7)) + (Ref(H, -7) > Ref(H, -8)) + (Ref(H, -9) > Ref(H, -10)) +
					  (Ref(H, -10) > Ref(H, -11)) + (Ref(H, -11) > Ref(H, -12)) + (Ref(H, -12) > Ref(H, -13)) +
					  (Ref(H, -13) > Ref(H, -14)) + (Ref(H, -14) > Ref(H, -15)) + (Ref(H, -15) > Ref(H, -16)) +
					  (Ref(H, -16) > Ref(H, -17)) + (Ref(H, -17) > Ref(H, -18)) + (Ref(H, -18) > Ref(H, -19)) +
					  (Ref(H, -19) > Ref(H, -20)) + (Ref(H, -20) > Ref(H, -21)) + (Ref(H, -21) > Ref(H, -22)) +
					  (Ref(H, -22) > Ref(H, -23)) + (Ref(H, -23) > Ref(H, -24)) + (Ref(H, -24) > Ref(H, -25)) +
					  (Ref(H, -25) > Ref(H, -26)) + (Ref(H, -26) > Ref(H, -27)) + (Ref(H, -27) > Ref(H, -28)) +
					  (Ref(H, -28) > Ref(H, -29)) + (Ref(H, -29) > Ref(H, -30));

You could use the Sum function...
https://www.amibroker.com/guide/afl/sum.html

HigherHigh = H > Ref(H, -1); // High higher than previous bar high
NumHigherHighs = Sum(HigherHigh, 30); // Higher highs in last 30 bars

Filter = 1;
AddColumn(HigherHigh, "HigherHigh", 1);
AddColumn(NumHigherHighs, "NumHigherHighs", 1);

5 Likes