How to Compute MAE for Trades with Scale-In Entries

The default MAE statistic from the backtest computes the worst percentage loss of a trade from the first entry to the most adverse price (e.g. highest high for a short trade and lowest low for a long trade) during the lifespan of the trade. I would like to have an additional MAE, based on the actual worst P&L during the lifetime of the trade. What’s the best way to compute this?

Thanks.

In either case you would have to go CBT route.
Link to manual https://www.amibroker.com/guide/a_custombacktest.html

Example

MAE = trade.GetMAE();
MAE *= trade.EntryPrice / 100;
1 Like

@fxshrat, it seem that I need to get the first scale-in price, in order to compute say, the percentage MAE from the average cost per unit trade.EntryPrice.

I haven’t found any of object methods that can provide the equivalent value in the CBT guide. Please give me a pointer if you know what method I should look at.

It seems that my alternative is to cache this value in my scale-in code (via a static variable) so I can access it in CBT. Is that correct, or there is a better way?

You can track highest high / lowest low price since entry yourself either in CBT or in first phase depending where most of your code logic is.
For example in CBT, when trade is open, you can access corresponding symbol current bar high/low using trade.GetPrice method. If it makes new high / new low you simply update hh/ll that you are tracking.