Test Results

 

After completion of a Test Run using the Strategy Tester, how can I export the records from the "Results" tab from the "Tester" panel of MT4 into a "CSV" formated file?

 
extern double Lots = 0.1;
extern string FileName="AcctHist.CSV" ;

int handle ;

static datetime cTime ;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   cTime=Time[0] ;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
  datetime howlong ;
  handle=FileOpen(FileName,FILE_CSV|FILE_WRITE,",");   
  if(handle>0)
    {
     Print("History total",OrdersHistoryTotal() ) ;
     FileWrite(handle, "Ticket","Magic","OTime","Type","Lots","Symbol","OPrice","S/L","T/P","CTime","CPrice","Swap","Profit","Comment","Time Open");     
     for(int i=0;i<OrdersHistoryTotal();i++)
      {       
       OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) ;
       howlong = OrderCloseTime()-OrderOpenTime() ;
       FileWrite(
         handle,
         OrderTicket(),                //int
         OrderMagicNumber(),           //int
         TimeToStr(OrderOpenTime()),   //datetime
         oType2str(OrderType()),       //int
         OrderLots(),                  //double
         OrderSymbol(),                //string
         OrderOpenPrice(),             //double
         OrderStopLoss(),              //double
         OrderTakeProfit(),            //double
         TimeToStr(OrderCloseTime()),  //int
         OrderClosePrice(),            //double
         OrderSwap(),                  //double
         OrderProfit(),                //double
         OrderComment(),                //string
         howlong
                  
        ) ; //end file write
      } //end for
     FileClose(handle);
    }   
//----
   return(0);
  }
You can either search for the filename after or to look in \MetaTrader install location\tester\files
 
rfileger:

After completion of a Test Run using the Strategy Tester, how can I export the records from the "Results" tab from the "Tester" panel of MT4 into a "CSV" formated file?

Save the report, copy the data from the report to a spreadsheet. Export as CSV.
 

You will also need

////////////////
string oType2str(int type)
{
switch (type)
  {
   case OP_BUY : return("Buy") ;// - buying position,
   case OP_SELL : return("Sell") ; //- selling position,
   case OP_BUYLIMIT : return("Buy Limit") ; //- buy limit pending position,
   case OP_BUYSTOP : return("Buy Stop") ; //- buy stop pending position,
   case OP_SELLLIMIT : return("Sell Limit") ; //- sell limit pending position,
   case OP_SELLSTOP : return("Sell Stop") ; //- sell stop pending position.
   default : return ("Other") ;//for depost withtrawal adjustments etc   
  }
} //end oType2str

to make it work and to put orders in correct time order

for(int i=OrdersHistoryTotal()-1;i>=0;i--)
 
rfileger:

After completion of a Test Run using the Strategy Tester, how can I export the records from the "Results" tab from the "Tester" panel of MT4 into a "CSV" formated file?


I was able to save the results via "Copy All" into a directory OUTSIDE of MetaTrader. Also, I was able to save the report via "Save as Report" into a directory OUTSIDE of MetaTrader.

If I saved to a directory inside of MetaTrader the "Save Dialog Box" could see the files but Windows Explorer CANNOT see the saved files which are saved under MetaTrader directory structure.

 
rfileger:


I was able to save the results via "Copy All" into a directory OUTSIDE of MetaTrader. Also, I was able to save the report via "Save as Report" into a directory OUTSIDE of MetaTrader.

If I saved to a directory inside of MetaTrader the "Save Dialog Box" could see the files but Windows Explorer CANNOT see the saved files which are saved under MetaTrader directory structure.

Do not install MT4 to ProgramFiles under Vista or Windows 7 unless you understand how to handle the UAC issues, install to C:\MT4_Installs\
Reason: