Новая версия платформы MetaTrader 5 build 1930: Плавающие окна графиков и .Net библиотеки в MQL5 - страница 87

 

Sigh!

  1. Print() doesn't work during the optimization - ok!
  2. So I want to use WinApi Print and failed: dll not alowed?
  3. I'd like to help you about the returns of OnTester() - if I only knew how!

This was my try:

double OnTester() {
   double dd = sqrt(TesterStatistics(STAT_BALANCE_DDREL_PERCENT)),
          oD = (TesterStatistics(STAT_BALANCE_DDREL_PERCENT)),
          pr = TesterStatistics(STAT_PROFIT);
   if (dd == 0.0) return(100.0*pr);
   if ( ((int)TimeLocal())%5000 == 0 ) {
      int wHdl = OpenExistingFileForReading("B:\\StratTester.txt",false,false); //my Windows function B: = ram disk
      int bRead[1];
      int szFile = GetFileSize(wHdl, bRead); //my Windows function
      CloseHandle(wHdl);
      if ( bRead[0] < 5000 )
         //my Windows function:
         AppendWriting(
            "B:\\StratTester.txt",
            StringFormat("%s  otgDD%% %s  sqrt(DD%%) &s  Profit %s  ret %s", 
                        _t2Sec(TimeLocal()),_d25(oD),_d25(dd),_d22(pr),_d23(pr/dd))
         );
   }
   return ( pr/dd );
}

I am not sure about FrameNext as the function "moves the pointer" and this might mess up the optimization?

 
Carl Schreiber:

I am not sure about FrameNext as the function "moves the pointer" and this might mess up the optimization?

FrameNext is intented to get data from Frame which are sending by tester agents by FrameAdd. It is like iterator for traversing all frames

See also sample in https://www.mql5.com/de/articles/403

Veranschaulichung einer Strategie im Prüfprogramm von MetaTrader 5
Veranschaulichung einer Strategie im Prüfprogramm von MetaTrader 5
  • www.mql5.com
Jeder kennt den Spruch: „Ein Bild sagt mehr als tausend Worte.“ Man kann zig Bücher über Paris oder Venedig lesen, aber die geistigen Vorstellungen vermitteln einem nie dasselbe Gefühl wie ein Spaziergang durch die abendlichen Straßen. Der Vorteil der Veranschaulichung oder der grafischen Darstellung lässt sich auf jeden beliebigen...
 
Rashid Umarov:

FrameNext is intented to get data from Frame which are sending by tester agents by FrameAdd. It is like iterator for traversing all frames

See also sample in https://www.mql5.com/de/articles/403


 

Ok - I tried this:

double OnTester() {
   double dd = sqrt(TesterStatistics(STAT_BALANCE_DDREL_PERCENT)),
          oD = (TesterStatistics(STAT_BALANCE_DDREL_PERCENT)),
          pr = TesterStatistics(STAT_PROFIT);
   if (dd == 0.0) return(100.0*pr);
   
   string name ="";  // Public name/frame label
   ulong  pass =0;   // Number of the optimization pass at which the frame is added
   long   id   =0;   // Public id of the frame
   double val  =0.0; // Single numerical value of the frame
   double stat_values[];
   FrameNext(pass,name,id,val,stat_values);
    
   if ( true ) { // pass%1 == 0 ) {
      PrintFormat("%s  pass %i  otgDD%% %s  sqrt(DD%%) &s  Profit %s  ret %s", 
                  TimeToString(TimeLocal(),TIME_SECOND),pass,DoubleToString(oD,5),DoubleToString(dd,5),DoubleToString(pr,3),DoubleToString(pr/dd,5) );
   }
   return ( pr/dd );
}

and failed as Print() (and I guess PrintFormat()) isn't available in the StrategyTester.

 
Carl Schreiber:

Sigh!

  1. Print() doesn't work during the optimization - ok!
  2. So I want to use WinApi Print and failed: dll not alowed?
  3. I'd like to help you about the returns of OnTester() - if I only knew how!

Check this option


 
Carl Schreiber:

Ok - I tried this:

and failed as Print() (and I guess PrintFormat()) isn't available in the StrategyTester.

Sure, it is written


 
Rashid Umarov:

Check this option


It is enabled, but despite that I thought that the tester agents (even the local ones as I don't use the cloud yet) don't accept dlls.

 
Carl Schreiber:

 I thought that the tester agents (even the local ones as I don't use the cloud yet) don't accept dlls.

Do you use remote agents in your home network?

 
Rashid Umarov:

Do you use remote agents in your home network?

No, even not the MetaTester Agents of the cloud on my pc. Just the one that has come with the terminal.

 

I finally got it by appending line by line to a file in the Common folder:

double OnTester() {
   double dd = sqrt(TesterStatistics(STAT_BALANCE_DDREL_PERCENT)),
          oD = (TesterStatistics(STAT_BALANCE_DDREL_PERCENT)),
          d1 = TesterStatistics(STAT_BALANCEDD_PERCENT),
          d2 = TesterStatistics(STAT_BALANCE_DDREL_PERCENT),
          d3 = TesterStatistics(STAT_EQUITYDD_PERCENT),
          d4 = TesterStatistics(STAT_EQUITY_DDREL_PERCENT),
          pr = TesterStatistics(STAT_PROFIT);
   if (dd == 0.0) return(100.0*pr);
   
   string name ="";  // Public name/frame label
   ulong  pass =0;   // Number of the optimization pass at which the frame is added
   long   id   =0;   // Public id of the frame
   double val  =0.0; // Single numerical value of the frame
   double stat_values[];
   FrameNext(pass,name,id,val,stat_values);
    
   if ( true ) { // pass%1 == 0 ) { 
      addLineToFileCommon(StringFormat("pass: %i  %s  d1 %05.2f  d2 %05.2f  d3 %05.2f  d4 %05.2f  org DD%% %05.2f  sqrt(DD%%) %05.2f  Profit %07.2f  ret %07.2f\n", 
                     pass,TimeToString(TimeLocal(),TIME_SECONDS),(d1),(d2),(d3),(d4),(oD),(dd),(pr),(pr/dd)),
                    "StratTest.txt");
         
   }
   return ( pr/dd );
}

The percent values are provided from 0 to 100.

But pass is always 0 (?) and TimeLocal always 23:59:59:

pass: 0  23:59:59  d1 06.07  d2 06.23  d3 07.06  d4 07.06  org DD% 06.23  sqrt(DD%) 02.50  Profit 1887.75  ret 0756.32
pass: 0  23:59:59  d1 05.15  d2 05.15  d3 05.57  d4 05.57  org DD% 05.15  sqrt(DD%) 02.27  Profit 1834.59  ret 0808.75
pass: 0  23:59:59  d1 07.56  d2 07.56  d3 08.75  d4 08.75  org DD% 07.56  sqrt(DD%) 02.75  Profit 2517.04  ret 0915.20
pass: 0  23:59:59  d1 04.43  d2 04.43  d3 04.96  d4 05.00  org DD% 04.43  sqrt(DD%) 02.10  Profit 1269.95  ret 0603.46
pass: 0  23:59:59  d1 29.40  d2 29.40  d3 31.47  d4 31.47  org DD% 29.40  sqrt(DD%) 05.42  Profit 1681.97  ret 0310.20
pass: 0  23:59:59  d1 05.99  d2 05.99  d3 06.45  d4 06.45  org DD% 05.99  sqrt(DD%) 02.45  Profit 4818.85  ret 1968.58
pass: 0  23:59:59  d1 08.34  d2 10.58  d3 08.72  d4 11.26  org DD% 10.58  sqrt(DD%) 03.25  Profit 3601.66  ret 1107.45
pass: 0  23:59:59  d1 17.19  d2 17.19  d3 18.71  d4 18.71  org DD% 17.19  sqrt(DD%) 04.15  Profit 5000.31  ret 1206.16
pass: 0  23:59:59  d1 25.16  d2 25.16  d3 25.27  d4 25.27  org DD% 25.16  sqrt(DD%) 05.02  Profit 5833.76  ret 1163.09
pass: 0  23:59:59  d1 14.95  d2 14.95  d3 12.12  d4 14.91  org DD% 14.95  sqrt(DD%) 03.87  Profit 8916.67  ret 2305.88
pass: 0  23:59:59  d1 29.67  d2 29.67  d3 30.37  d4 30.37  org DD% 29.67  sqrt(DD%) 05.45  Profit 2715.90  ret 0498.64
pass: 0  23:59:59  d1 09.72  d2 11.26  d3 10.79  d4 12.31  org DD% 11.26  sqrt(DD%) 03.36  Profit 6876.42  ret 2049.58
pass: 0  23:59:59  d1 17.35  d2 17.35  d3 17.22  d4 17.22  org DD% 17.35  sqrt(DD%) 04.17  Profit 7261.55  ret 1743.23
pass: 0  23:59:59  d1 11.93  d2 11.93  d3 12.09  d4 12.09  org DD% 11.93  sqrt(DD%) 03.45  Profit 4979.16  ret 1441.58

This is the corresponding table of the optimization:


Interesting to see the table shows 15 lines my file only 14. The first entry is missing. But the counter shows 13:


The empty line of the table corresponds to this log-entry:

2018.12.20 17:24:24.531 Core 05 genetic pass (0, 2) tested with error "incorrect input parameters" in 0:00:00.250

And this shows that - I guess - the 'non-passes' due to "return(INIT_PARAMETERS_INCORRECT)" or "return(INIT_FAILED)" still is counted by the Tester and the genetic Algorithm:

2018.12.20 17:24:47.636    Tester    genetic optimization finished on pass 15 (of 1048576)
2018.12.20 17:24:47.636    Statistics    optimization done in 0 minutes 26 seconds
2018.12.20 17:24:47.638    Statistics    shortest pass 0:00:00.250, longest pass 0:00:23.120, average pass 0:00:10.869
2018.12.20 17:24:47.638    Statistics    local 15 tasks (100%), remote 0 tasks (0%), cloud 0 tasks (0%)
2018.12.20 17:24:47.654    Tester    15 new records saved to cache file 'tester\cache\NewEAb v003.EURUSD.H1.20170108.20171223.11.32E03FFA9573C89D9A9C8BF2DFA77676.opt'