Is there a way to link both in and out deal together in MT5 backtest report?

dreamsky2007  

In MT5, the order/deal, in/out position are separated unlike MT4.

the backtesting report does provide "order id" in "deal" table at the bottom. But somehow i cant really find the position ID so that i can generate a table just like MT4 report.


Does any know how to link the in and out deal?

Enrique Dangeroux  

Snippet from my code. Does not compile but gives the idea.

#include <Trade\DealInfo.mqh>
#include <Generic\HashMap.mqh>
   
   CDealInfo         deal;

   bool res=HistorySelect(0,INT_MAX);
   if(!res)
     {
      err_msg="Unable to get the trade history";
      return(false);
     }

   int deals_total=HistoryDealsTotal();
   ulong ticket_in = 0;
   
   for(int i=0; i<deals_total; i++)
     {
      if(!deal.SelectByIndex(i))
        {
         err_msg="Unable to select ticket";
         return(false);
        }
        
      if(deal.Entry()==DEAL_ENTRY_IN )
        {
         HashMap.Add(deal.PositionId(),deal.Ticket());
        }
        
      if((deal.Entry()==DEAL_ENTRY_OUT || deal.Entry()==DEAL_ENTRY_INOUT || deal.Entry()==DEAL_ENTRY_OUT_BY)) //
        {
          if(HashMap.TryGetValue(deal.PositionId(),ticket_in))
            {
              OpenPrice = HistoryDealGetDouble(ticket_in, DEAL_PRICE);  // Get data from ticket in
              ClosePrice = deal.Price();  				// Get data from ticket out
            }
        }
     }

There are many nuances for generating a correct report. The standard report in MT5 is flawed in many ways and can lead to self deception.

For example, position closed by OUT_BY will skew the metrics because MT5 considers it as two trades, not sure about MT4 but i suspect the same. 

Another example is INOUT. One trade can be a series of 1000 deals. The standard report will show one trade.

dreamsky2007  
Enrique Dangeroux:

Snippet from my code. Does not compile but gives the idea.

There are many nuances for generating a correct report. The standard report in MT5 is flawed in many ways and can lead to self deception.

For example, position closed by OUT_BY will skew the metrics because MT5 considers it as two trades, not sure about MT4 but i suspect the same. 

Another example is INOUT. One trade can be a series of 1000 deals. The standard report will show one trade.

Thank you for your reply. I do not write my EA at the moment but more on analyzing the standard report generated in MT5.

as you mentioned, the standard report in MT5 is flawed and kind of defeat the purpose of showing the detail without position id.


for real life trades, I manage to use Python to link both IN position_id and OUT position_id to figure out trade duration, pips generated and even manage to link to Order to figure out slippage.
Do you think MQL will improve the standard report? i just hope they add just position_id column in standard MT5 report... Do they even accept suggestion?


import MetaTrader5 as mt5
from datetime import datetime
import pandas as pd

...

deals=mt5.history_deals_get(from_date, to_date, group="*")
    if (len(deals)>0):
        deals_pd = pd.DataFrame(deals,columns=deals[0]._asdict().keys())
Enrique Dangeroux  

I do not think it will change. It has not changed since i started using the terminal in 2017. The metrics for signals is calculated in the same way. For comparison it is fine if equally flawed.

Anyway. It is best practice to not rely on any change from MQ and build your own tools. Almost everything is possible to make yourself. I do not use the standard report at all and use my own reporting tools.

dreamsky2007  
Enrique Dangeroux:

I do not think it will change. It has not changed since i started using the terminal in 2017. The metrics for signals is calculated in the same way. For comparison it is fine if equally flawed.

Anyway. It is best practice to not rely on any change from MQ and build your own tools. Almost everything is possible to make yourself. I do not use the standard report at all and use my own reporting tools.

I'm testing most EA from MQL market before buying them. 

tbh, i'm also found the Python package they provided have minor flaw (but doesnt really matter for my use case at the moment). 

it is sad to see that the tools provided is flawed for so many years.


if the person wanted to purchase EA from MQL market, it seems like the only option available is to rely on their flawed tester and report which sometimes doesnt help if we would like to know more.


Do you know is there any other external tools that can help to test EA written by others? assume we have totally no access to append any codes to generate report.

Reason: