Feature: MFE/ MAE Analysis

When optimizing a strategy, it is helpful to analyze the trades that a strategy has taken. While TuringTrader offers the complete order log for analysis, it was a bit harder to extract the information required for MFE/ MAE analysis. We have changed that with the latest release.

Order Log

Whenever TuringTrader executes an order, a new entry is written to the order log. The order log entries contain the following elements:

TuringTrader order log

We see that the order log entries also contain the original order ticket, containing the following elements:

TuringTrader order

Entry + Exit = Position

This info allows us to fully reconstruct the situation that led to placing each order. But for a complete analysis of how a trade developed, we need to know what was going on between entry and exit.

The first thing we need to do, is to group entries and exits together, to form positions. This is what TuringTrader’s LogAnalysis class does for us in a simple step:

TuringTrader order log analysis

Please note that the entries and exits can be grouped either using the Last-In-First-Out, or the First-In-First-Out methods.

The trade log is a list of positions with the following fields:

TuringTrader trading log

Calculating MFE and MAE

We’ve had the ability to group entry and exit orders to positions for a little while now. What’s new, are the two fields HighestHigh, and LowestLow. These two fields allow us to calculate the Maximum Favorible Excursion (“MFE”), and the Maximum Adverse Excursion (“MAE”). Here is some sample code putting this all together:

TuringTrader MFE/ MAE Analysis

This code will produce a log looking like this:

TuringTrader MFE/ MAE Analysis

The information is all there, now it’s up to you to use it. How about creating a scatter plot, instead of writing to a table?

Happy coding!