Libraries: Report - page 6

 
 

Hi!

I have generated some information from deals. I am also writing a code for drawdowns, currently in beta :)

Files:
 
Arthur Albano:

Hi!

I have generated some information from deals. I am also writing a code for drawdowns, currently in beta :)

Trading results. Are these results good on a demo account?

Trading results
 
 
Cross-platform alternative balance chart

Forum on trading, automated trading systems and testing trading strategies

Scripts: Balance Graph HTML

fxsaber, 2019.04.08 09:16

For MT4/5.
// MQL4&5-code

#property strict

// Copy "Graph.txt" to "Files\Graph.txt".
// https://www.mql5.com/en/code/25199
// #resource "\Scripts\Graph_HTML\Resource\Graph.txt" as string htm_file

#import "shell32.dll"
  int ShellExecuteW( int hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd );
#import

#ifdef __MQL5__
  #include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006

  #define  BASEPATH (TerminalInfoString(TERMINAL_PATH) + "\\MQL5\\Files\\")
#else // __MQL5__
  #define  BASEPATH (TerminalInfoString(TERMINAL_PATH) + "\\MQL4\\Files\\")
#endif // __MQL5__

bool CreateBalanceData( const string FileName = "exdat.txt" )
{
  const int handle = FileOpen(FileName, FILE_WRITE | FILE_TXT | FILE_ANSI);
  const bool Res = (handle != INVALID_HANDLE);

  if (Res)
  {
  // https://www.mql5.com/ru/forum/170953/page14#comment_10550116
  #define  CLOSETIME_INDEX 0
  #define  TICKET_INDEX 1
    long Tickets[][2];
    int Total = OrdersHistoryTotal();    

  #ifdef __MQL5__
    static const bool Sort = false;
  #else // __MQL5__
    #ifdef __VIRTUAL__
      static const bool IsTester = ::MQLInfoInteger(MQL_TESTER);

      const bool Sort = !IsTester && !VIRTUAL::GetHandle();
    #else // __VIRTUAL__
      static const bool Sort = !::MQLInfoInteger(MQL_TESTER);
    #endif // __VIRTUAL__

    if (Sort)
    {
      int Amount = 0;

      for (int i = (::ArrayResize(Tickets, Total) >> 1) - 1; i >= 0; i--) // https://www.mql5.com/ru/forum/170953/page16#comment_10604064
        if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
        {
          Tickets[Amount][CLOSETIME_INDEX] = OrderCloseTime();
          Tickets[Amount++][TICKET_INDEX] = OrderTicket();
        }

      if ((bool)(Total = ::ArrayResize(Tickets, Amount) >> 1)) // https://www.mql5.com/ru/forum/170953/page16#comment_10604064
        ::ArraySort(Tickets);
    }
  #endif // __MQL5__
    
    double Balance = 0;

    FileWriteString(handle, "var dat1=[\n");

    for (int i = 0; i < Total; i++)
      if ((Sort ? OrderSelect((int)Tickets[i][TICKET_INDEX], SELECT_BY_TICKET) : (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))) && // int - (Sort == true) only for MQL4.
          ((OrderType() <= OP_SELL) || (OrderType() > OP_SELLSTOP)))
    #undef  TICKET_INDEX
    #undef  CLOSETIME_INDEX
      {
        Balance += OrderProfit() + OrderCommission() + OrderSwap();

        FileWriteString(handle, "[" + (string)((long)OrderCloseTime() * 1000) + "," + DoubleToString(Balance, 2) + "],\n");
      }

    FileWriteString(handle, "];\n");
    FileWriteString(handle, "var T1=dat1[0][0];\n");
    FileWriteString(handle, "var T2=dat1[dat1.length-1][0];\n");
    FileWriteString(handle, "var nTrades=dat1.length;\n");
    FileWriteString(handle, "var Balance=" + DoubleToString(Balance, 2) + ";\n");
    FileWriteString(handle, "var Currency=\"" + AccountInfoString(ACCOUNT_CURRENCY) + "\";\n");

    FileClose(handle);
  }

  return(Res);
}

string GetHTM( const string FileName = "Graph.txt" )
{
  uchar Data[];

  const int handle = FileOpen(FileName, FILE_READ | FILE_BIN);
  const bool Res = (handle != INVALID_HANDLE);

  if (Res)
  {
    FileReadArray(handle, Data);

    FileClose(handle);
  }

  return(Res ? CharArrayToString(Data) : NULL);
}

//+------------------------------------------------------------------+
//| Creates 'HighCharts' balance report on trades in .html format |
//+------------------------------------------------------------------+
void CreateHighChartsBalanceReport( const string FileName = "Graph.htm" )
{
  const int handle = FileOpen(FileName, FILE_WRITE | FILE_TXT | FILE_ANSI);

  if (handle != INVALID_HANDLE)
  {
// FileWriteString(handle, htm_file);
    FileWriteString(handle, GetHTM());
    FileClose(handle);

    if (CreateBalanceData())
      ShellExecuteW(0, "Open", BASEPATH + FileName, NULL, NULL, 3);
  }
}

void OnStart()
{
  CreateHighChartsBalanceReport();
}



Different from Report - interactive chart with various contrivances.

Balance Graph HTML
Balance Graph HTML
  • www.mql5.com
Pan PrizMA Sin leverage 72 Builds a sliding line with a polynomial of 4 degrees. Extrapolates as a section of a given function with a sinusoid and its axial one. One value is taken from the constructed lines on each bar and a line of extrapolated values is plotted...
 

Excellent tool. However, when running forward tests, it only saves the backtest report and balance.

Any suggestion on how to save forward tests too?


F

 
A new feature has been added. Example of application to a standard Expert Advisor.
#define  REPORT_TESTER             // The tester will automatically record reports
#define  REPORT_TESTER_INPUTS      // The single pass report will show EA input parameters - requires DLL resolution.
#define  REPORT_INTERACTIVE_CHARTS // Adds interactive graphs to the report.
#define  REPORT_BROWSER            // Creating a report with browser startup - requires DLL permission.
#include <Report.mqh> // https://www.mql5.com/en/code/18801

#include <..\Experts\Examples\Moving Average\Moving Average.mq5>


In the trailer is the result of launching a single pass. Now you can see the input parameters of the Expert Advisor and the interactive balance chart.


ZY CustomReport script has been updated. Try a non-static trading report on your account. Example of work.

Files:
Reports.zip  138 kb
 

Finally single passes became full-fledged - all charts appeared in the report.

Also in MT4 for all brokers in the report added data on slippages when executing TP/SL. To do this, you need to update the library.

 

Tester settings have been added to the single pass reports.


 

Unexpectedly it turned out that despite the constant use of MT5-Tester, I completely stopped looking at the Backtest and Chart tabs.

When I need to calculate faster or set conditions for order execution, commission size, I do everything through Virtual.

The convenience is that you don't need to know Virtual or Report at all. I just write the same lines in the beginning and MT5-Tester is transformed.