Well, without looking at your full script:
* How do you even know that you are only counting the long trades? I see no use of TradeIsLong. Isolate, isolate, isolate.
* I suggest printing detailed information about every trade for debugging purposes.

https://zorro-project.com/manual/en/fortrades.htm
https://zorro-project.com/manual/en/trade.htm