@Andy Matt's solution is excellent and you were correct to look for a more elegant solution. I thought this might be a useful opportunity to show that often there are many ways to achieve the same result in AmiBroker. The real programmers out there can discuss the advantages and disadvantages of the solutions as I am not a programmer so am uncertain what's best.
But for an example if you were looking for 3 consecutive "Up" closes or N consecutive "Up" bars some possible solutions, (Here I give a shout out to Cesar Alvarez, Matt's old colleague who taught me variations on the following)
// Different ways of coding Close Up N_Bars days in a row
N_Bars = Param( "N_Bars", 3, 1, 10, 1 );
Method1 = Sum( C > Ref( C, -1 ), N_Bars ) == N_Bars;
Method2 = Sum( ROC( C, 1 ) > 0, N_Bars ) == N_Bars;
Method3 = BarsSince( C <= Ref( C, -1 ) ) >= N_Bars;
Method4 = BarsSince( ROC( C, 1 ) <= 0 ) >= N_Bars;
Method5 = HHV( ROC( C, 1 ) <= 0, N_Bars ) == 0;
Produce the same result which when I use an Explore to debug looks like this,
And there are probably more ways to come up with that too. As you coded a simple method if it was just for 3 bars, perhaps not "elegant" but they work.
Up3 = C > Ref( C, -1 ) and Ref( C, -1 ) > Ref( C, -2 ) and Ref( C, -2 ) > Ref( C, -3 );
AnotherUp3 = ROC( C, 1 ) > 0 and Ref( ROC( C, 1 ), -1 ) > 0 and Ref( ROC( C, 1 ), -2 ) > 0;