In this code my condition is meant to count each bar between 8am and 9am each day on the 5m chart.

I am happy with this code as it does the job okay but have i written too much code for such a simple task? I couldnt figure out how i might use predefined Bars variable because it only counts all bars on chart when i wanted to only count when a condition is true?

Unless you are expecting no activity during an entire 5mins, there are usually 12 M5 bars in an Hour.

However, you can also use "iBarShift()" to get an index for a start date/time and as well as an index for end date/time.The difference of the two indices will give you the number of bars in between those two dates/times.