Is there a way to count green/red candles in a period?
Yes, create a variable to store the green count, and another variable to store the red count.
Run a loop through your period. For each candle, if the open is less than the close it is a green candle. Otherwise it is a red candle. You need to decide what you want to do with dojis.
The code varies depending on whether this is MQL4 or MQL5.