Ok I have tested your function and something happens...
Regarding the ticks flag. I trade the strategy in normal 1h mode and test in the ticks mode.

As you mentioned the calculations seems correct, even some trade are slightly over the limit set. Unfortunately the MAE graph shows a totally different picture.
I can see only 2 Options:
- the trade are not stopped properly
- the MAE graph is incorrect.

The TradeMAE is price difference, accordingly with the manual. the TradeMAE should be size independent.

I will work on a TMF that will close the trade at a specific pip loss and see what happen should be the same than set Stop = 200* Pip;

ciao