Zorro's example on "Equity curve trading" that you are following is wrong: your "total_equity" and "max_equity" are series, i.e. are updated at each BAR (have no connection to each Trade).
(When a system is out of the market - guess what will happen?)

Because of this, in your loop you make comparisons of exactly the same values and increment Count "closed_trades" number of times.

To implement this correctly, you have several options:

- use static series and update it manually at trade exit: ( http://manual.zorro-trader.com/shift). Then you do not need a for(closed_trades) loop.
- at trade exit (in a tmf) save Equity to a TradeVar and separately keep track of the max Equity(no need for a series). Then you access TradeVars and compare these in for(trades) loop and increment Count as needed.