Automated Optimization procedure EA using library ?

 

hello guys!
I have read this interesting article:
https://www.mql5.com/en/code/10360
Automated process of backesting using a library.

Is there something similar for optimization ?

I need to repeat the process of optimizing an EA for different periods and collect all the results of optimization in a file to see which sets are repeated more often.


Thank you very much
!

 
 
Look this, if is a kind of helpfull:

Automated Optimization Methods

https://www.mql5.com/en/forum/140187
 
RaptorUK:
Have a read of this: https://www.mql5.com/en/forum/138637


Thank you RaptorUK, i read, work fine but i have the report of optimization but i don't have the "result of optimization":

; start strategy tester
TestExpert=Moving Average
TestExpertParameters=ma0.set
TestSymbol=EURUSD
TestPeriod=H1
TestModel=2
TestOptimization=false
TestDateEnable=true
TestFromDate=1970.01.01
TestToDate=2006.06.06
TestReport=MovingAverageReport
TestReplaceReport=false
TestShutdownTerminal=true

Do You can suggest a script or library where is obtained these data?

Thank's a lot

 
blap:
Look this, if is a kind of helpfull:

Automated Optimization Methods

https://www.mql5.com/en/forum/140187

Blap thank's !!!
 

I take a look at this article: https://www.mql5.com/en/articles/1498

I modified the file auto_optimization_204 but at this point:

// Read from file into the array
// Cycle, until the file ends
while(FileIsEnding(file) == false)
  {                 
    // Read a string from the report file
    FileLine = FileReadString(file);
    // Find the necessary string and set the reference point there
    index = StringFind(FileLine, "title", 20);
    if(index > 0)
      {
        // Increase the array in size
        ArrayResize(ArrayStrg, NumStr + 1);
        // Record the strings from the file in the array
        ArrayStrg[NumStr] = FileLine;
        NumStr++;
      }
  }
// Close the file
FileClose(file);
// Delete the file in order not to produce too many copies
FileDelete(FileReport);
// Set the array size by the amount of data read from the file
ArrayResize(ArrayData, NumStr); strings

i have this error:

Why? Please help.

thank's

Files:
opt.zip  19 kb
 

if I'm not mistaken this variable is not related of open file

This is the first part of the library:

//+------------------------------------------------------------------+
//|                                        auto_optimization_204.mqh |
//|                                           Copyright © 2006, XEON |
//|                                                       xeon@nm.ru |
//+------------------------------------------------------------------+
//-------------------------------------------
#import  "shell32.dll"                                                       //Ïîäêëþ÷èì dll (âõîäèò â ñîñòàâ windows)       
  int ShellExecuteA(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd); 
#import
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int Tester(string Daystart, string Daystop, int TestDay,string NameMTS,string NameFileSet,string PuthTester,int TimeOut,int Gross_Profit,int Profit_Factor,int Expected_Payoff,string Per1,string Per2,string Per3,string Per4)
  {
  // Path to the terminal 
   string PuthTerminal    =  TerminalPath()+"\\tester\files";                        // TerminalPath()+"\experts\files";     sbgagliato  \\tester\files
   // Name of the ini file for the tester                
   string FileOptim       = "optimise.ini";                                   
   string FileOptim1      = "\optimise.ini";   
   // Calculation of the starting date                             
   datetime DayStart      = TimeLocal()-86400*TestDay;                        
   // Optimization starting date
   string DateStart       = Daystart;                    
   // Optimization ending date
   string DateStop        = Daystop;               
   // Tester report file name
   string FileReport      = "FileReport_"+Symbol()+"_"+DateStop+".htm";       
   string FileReport1     = "\\FileReport_"+Symbol()+"_"+DateStop+".htm";
   // Limitation for the minimum amount of trades per day
   double MinTr           = TestDay-2;                                       
   // Limitation for maximal amount of trades per day
   double MaxTr           = (60/Period()*TestDay)+2;                          
   // The amount of attempts to copy the report file
   int    KvoPptk         = 10;                                               
   // The amount of lines for sorting
   int    StepRes         = 12;                                               
//-------------------------------Ïðî÷èå ïðîìåæóòî÷íûå ïåðåìåííûå------------------------
   int    copyini,start,opttim,file,Pptk,OptimArraySize;
   int    P1,P2,P3,P4,P1k,P2k,P3k,P4k;
   int    ClStep,ClStepRazm,GrProf,GrProfRazm,TotTrad,TotTradRazm,ProfFact,ProfFactRazm,ExpPay,ExpPayRazm;
   int    text,index,kol,NumberStr,NumStr,test,CopyAr;
   int    GrosPr,PrCycle,Dubl;
   int    ResizeArayNew;
   double kol1,kol2,kol3,kol4,kol5,kol6,kol7,kol8,kol9;
   double TotalTradesTransit,GrossProfitTransit,ExpectedPayoffTran;
   double PrFactDouble;
   double Prior1, Prior2, Prior3, transit, transit1, transit2, transit3, transit4;
   double NewPrior, NewPrior1, NewPrior2, NewPrior3, Sort, SortTrans;
   string FileLine; 
   string ini;
   string CycleStep,GrossProfit,TotalTrades,ProfitFactor,ExpectedPayoff;
   string Perem1,Perem2,Perem3,Perem4; 
   string select;
   bool   nodubl;
//----------------------------------- Ïîäãîòîâèì ìàññèâû -------------------------
   string ArrayOpttim[15]; 
   string ArrayStrg[10]; 
   double ArrayData[10][9]; 
   double ArrayTrans[10][9];
//------------------------------Ïîäãîòîâèì ini ôàéë äëÿ îïòèìèçàöèè----------------
   ArrayOpttim[0] = ";optimise strategy tester";             
   ArrayOpttim[1] = "ExpertsEnable=false";                        //Âêë/Âûêë ýêñïåðòû
   ArrayOpttim[2] = "TestExpert="+NameMTS;                        //Íàèìåíîâàíèå ôàéëà ýêñïåðòà
   ArrayOpttim[3] = "TestExpertParameters="+NameFileSet;          //Íàèìåíîâàíèå ôàéëà ñ ïàðàìåòðàìè
   ArrayOpttim[4] = "TestSymbol="+Symbol();                       //Èíñòðóìåíò
   ArrayOpttim[5] = "TestPeriod=H1";                       //Ïåðèîä
   ArrayOpttim[6] = "TestModel="+2;                               //Ðåæèì ìîäåëèðîâàíèÿ
   ArrayOpttim[7] = "TestRecalculate=false";                      //Ïåðåñ÷èòàòü
   ArrayOpttim[8] = "TestOptimization=true";                      //Îïòèìèçàöèÿ
   ArrayOpttim[9] = "TestDateEnable=true";                        //Èñïîëüçîâàòü äàòó
   ArrayOpttim[10]= "TestFromDate="+DateStart;                    //Äàòà íà÷àëà òåñòèðîâàíèÿ
   ArrayOpttim[11]= "TestToDate="+DateStop;                       //Äàòà îêîí÷àíèÿ òåñòèðîâàíèÿ
   ArrayOpttim[12]= "TestReport="+FileReport;                     //Èìÿ ôàéëà îò÷åòà
   ArrayOpttim[13]= "TestReplaceReport=true";                     //Ïåðåçàïèñü ôàéëà îò÷åòà
   ArrayOpttim[14]= "TestShutdownTerminal=true";                  //Çàêðûòü òåðìèíàë ïî çàâåðøåíèþ
//------------------------------- Write data into the ini file    --------------------------                 
   OptimArraySize=ArraySize(ArrayOpttim);                         // Find out about the array size
   opttim=FileOpen(FileOptim,FILE_CSV|FILE_WRITE,0x7F);           // Open a file to write               E:\save\Trading\METATRADER\Alpari NZ MT4\tester\files
   if(opttim>0){
      for(int i=0; i<OptimArraySize; i++){
          ini=ArrayOpttim[i];                                     // from the array into the variable
          FileWrite(opttim, ini);                                 // from the variable into the file    E:\save\Trading\METATRADER\Alpari NZ MT4\tester\files
      } 
      FileClose(opttim);                                          // close the file
   }
   else{Print("Failed writing data into the ini file. Error No ",GetLastError());return(0);}
//--------------------------  copy the ini file into the tester folder ----------
   copyini = ShellExecuteA(0,"Open","xcopy","\""+PuthTerminal+FileOptim1+"\" \""+PuthTester+"\" /y","",3);
   Sleep(1200);                                                    // wait until the file is copied
   if(copyini<0){Print("Failed copying ini file");return(0);}
//---------------------------------- Start Tester  -------------------------
   start   = ShellExecuteA(0,"Open","terminal.exe",FileOptim,PuthTester,3);
   if( start<0){Print("Failed starting Tester");return(0);}
//------------------------ ñêîïèðóåì ôàéë îò÷åòà â ïåñî÷íèöó òåðìèíàëà -------
    Comment("Wait until optimization is complete"+TimeToStr(TimeLocal()+60*TimeOut,TIME_MINUTES));
    Sleep(60000*TimeOut);                                           // wait until optimization is complete
    for(Pptk=0;Pptk<KvoPptk;Pptk++){                                  //Start a cycle attempting to compy the resport file
        Comment("Attempt # "+Pptk+"to copy the report file");
        ShellExecuteA(0,"Open","xcopy","\""+PuthTester+FileReport1+"\" \""+PuthTerminal+"\" /y","",3);
        Sleep(1200);                                                // wait until the file is copied
        file=FileOpen(FileReport,FILE_READ,0x7F);                   // Try to open the report file
        if(file<0){Sleep(60000);}                                   // if it fails to open, wait some more and try again
        else break;             
    }
    if(file<0){Print("Failed copying the report file");return(0);}
//---------------- Read from file into the array----------------------------------

 
    while(FileIsEnding(file)==false){                               // Cycle, until the file ends
          FileLine=FileReadString(file);                            // Find the necessary string and set the reference point there
          index=StringFind(FileLine, "title", 20);   
          if(index>0){
             ArrayResize(ArrayStrg,NumStr+1);                       // Increase the array in size
             ArrayStrg[NumStr]=FileLine;                            // Record the strings from the file in the array
                      //     Print ("NumStr_ver",NumStr); 
             NumStr++;
    }}
    FileClose(file);                                                // Close the file
    FileDelete(FileReport);                                         // Delete the file in order not to produce too many copies
    ArrayResize(ArrayData,NumStr);                                  // Set the array size by the amount of data read from the file
    for(text=0;text<NumStr;text++){
        select=ArrayStrg[text]; 
//-------------------------------------------------------------------------; ">
 //   Reporting text processing (These are apples and oranges)        
thank you Ickrus for your attention!!!
 

Sorry all I can think of is to put Numbered Print statements {if(getlasterror()>0) Print("1",NumStr)} wherever ArrayReSize appears in the code to track it down rather than trying to hold all the varable values in my head.

As I look at the problem the obvious questions are

1 Where is NumStr created and with what value and

2 before it starts the being counted in the while loops what value did it start with.

There is a lot of code to go through trying to trace the answers to those questions.

Somewhere in the code there is an ArrayResize(ArrayName,intVarable) with the intVarable set to the value -1 not necessarily in the code snipet you posted.

As far as some quick testcode experiments tell me ArrayResize(MyArray,0) is an array with no elements ( no memory set aside to save data in)

and ArrayResize(MyArray,1) is an array with one reserved memory reference set aside and you /assign/access that data by using MyArray[0] ;

 
Edit previous post
 

and another check in the posted code tells me that NumStr is not initialised to any value until its used!

So the Line

   int    text,index,kol,NumberStr,NumStr,test,CopyAr;

should read

   int    text=0,index=0,kol=0,NumberStr=0,NumStr=0,test=0,CopyAr=0;
 

Thank you Ickrus for you time!

With file mqh i can't see the value of variabile with print function, then i put all in a file mq4 and I saw where it was the error.

thanks you

Reason: