I'm posting this here in case someone still looking for the answer. The function returns an integer bars count since a condition was true bool MyCondtion = close[i] > open[i]; int Counter = BarsSince(MyRule_1); ...