How to "count" certain events in a time series
Try generating a dictionary of patterns you want to identify.  You can then use convolutions/ cross-correlations to identify where these patterns appear in your data.
https://en.wikipedia.org/wiki/Convolution
https://en.wikipedia.org/wiki/Cross-correlation
http://paulbourke.net/miscellaneous/correlate/

This method is also called 'matched filter'.