Here is some example that I just made for someone else, but it calculates the loss instead of the count of trades in loss. It's the same idea.
I'm also preparing a block to load basket of trades and then to get different parameters for them (sum, max, min, average) in Condition, but I still don't like the way I did it. Sometimes in MQL4/MQL5 I need to do too many tricks with arrays, which unfortunately slows the backtest down a lot.