Reply

SQOrder Class MAE/MFE Properties Returning 0

6 replies

seaton

Customer, bbp_participant, community, 161 replies.

Visit profile

8 years ago #114154

I’ve just been playing around with my first chart and have done a MAE vs % Gain, all pretty simple and straight forward (I’m loving the ability to extend BTW) however the SQOrders class seems to be returning 0 for MAE and MFE properties?

 

Have just tried to attach the file and forum won’t allow me so have pasted it below.  

 

BTW would be nice to have a section in the forum to allow sharing of extensions as I’m happy to share mine.

package com.strategyquant.extend.TradeAnalysisPanes;

import java.util.ArrayList;


import org.jfree.chart.JFreeChart;


import com.strategyquant.lib.charts.common.SQChart;
import com.strategyquant.lib.charts.common.SQScatterChart;
import com.strategyquant.lib.charts.common.duration.TimeDuration;
import com.strategyquant.lib.language.L;
import com.strategyquant.lib.results.SQData;
import com.strategyquant.lib.results.SQOrder;
import com.strategyquant.lib.results.SQOrderList;
import com.strategyquant.lib.results.SQResultsGroup;
import com.strategyquant.lib.settings.SQConst;
import com.strategyquant.lib.snippets.TradeAnalysisChartPane;


public class MAEvsGainChart extends TradeAnalysisChartPane {
//private ArrayList<TimeDuration> timeDurationList;


public MAEvsGainChart() {
this.name = L.t("MAE vs Trade Outcome (% Gain)");
}


@Override
public JFreeChart drawChart(SQResultsGroup strategyResult, SQData data) {
SQScatterChart chart = new SQScatterChart();
chart.xLegend = L.t("% Gain");
      chart.yLegend = L.t("MAE");


if(strategyResult==null) {
return chart.render();
}


ArrayList<double[]> trades = computeData(strategyResult, data);


for(int trade=0; trade<trades.size(); trade++) {
double[] values = trades.get(trade);


if(values[1]<0) {
chart.add("losers", values[1], values[0]);
} else {
chart.add("winners", values[1], values[0]);
}
}


//chart.setDurationDomainAxis(true);
chart.setSeriesColor("losers", SQChart.COLOR_RED);
chart.setSeriesColor("winners", SQChart.COLOR_GREEN);


return chart.render();
}


private ArrayList<double[]> computeData(SQResultsGroup strategyResult, SQData data) {
ArrayList<double[]> trades = new ArrayList<double[]>();


SQOrderList orderList = filterOrders(strategyResult, data);


for(SQOrder order : orderList) {
double[] values = new double[2]; 
values[0] = order.MAE;
values[1] = order.PctPL;


trades.add(values);
}


return trades;
}
}

0

Tamas

Customer, bbp_participant, community, sq-ultimate, 73 replies.

Visit profile

8 years ago #132436

Hello seaton,

 

it should be easy to calculate MAE/MFE if you need them for your report.

They have to be calculated for particular set of orders.

 

First get the orders  

SQOrderList orderList = filterOrders(strategyResult, data);

 

then calculate MAE for each of order.

for(SQOrder order : orderList) {

   order.MAE = value;

}

 

Best regards,

Tomas

0

seaton

Customer, bbp_participant, community, 161 replies.

Visit profile

8 years ago #132454

Thanks Thomas,

 

I had incorrectly assumed that the MAE and MFE in each order was already calculated.

 

Thanks

0

seaton

Customer, bbp_participant, community, 161 replies.

Visit profile

8 years ago #132455

Actually when I was driving to work today I was pondering on this and there is no way to calculate MAE/MFE from within SQAnalyser as these numbers need to be captured during the trade/Backtest and therefore can’t be calculated by SQAnalyser.

 

As the Data I’m loading is from MT4 backtests that I’d saved, this information won’t be available as I’m pretty sure MT4 backtester doesn’t provide it, however with SQ backtests I think this is calculated internally so will test this.

0

seaton

Customer, bbp_participant, community, 161 replies.

Visit profile

8 years ago #132456

Just confirmed this is the case:

 

MAE/MFE is calculated in Strategy Quant and is NOT in MT4 backtests,  just one of the many deficiencies of MT4 as a platform sigh, anyway will debug on Strategy Quant tests to get it working correctly

0

seaton

Customer, bbp_participant, community, 161 replies.

Visit profile

8 years ago #132459

Ok this has led me to the next problem.

 

How is Strategy Quant calculating MAE/MFE as they appear to be incorrect?

 

1) MAE is being shown as Positive number, it should never be greater than 0, while MFE should never be less than 0

2) MAE and MFE values seem vey much the same, so am a bit sceptical of them.

 

These were taken from a StrategyQyant strategy loaded into SQ Analysis, similar results on different strategies.

 

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

8 years ago #132484

This needs to be verified. I also get different values of MAE/MFE in Analyzer when trying to import strategy generated in SQ

0

Viewing 6 replies - 1 through 6 (of 6 total)