report2set_codebase

Author: Igor Zakharov
Miscellaneous
Uses files from the file systemIt reads information from a fileIt writes information to file
0 Views
0 Downloads
0 Favorites
report2set_codebase
#property copyright   "Igor Zakharov"
#property version     "1.0"
#property link        "https://www.mql5.com/ru/users/igor.i"
#property description ""
#property description "Script converts OptimizationReport (htm) to EA set files (set)"

#property strict
#property show_inputs

extern string FileName  ="OptimizationReport"; // Report file name
extern string FolderName="Sets";               // Output folder
extern string prefix    ="";                   // set filename prefix
extern bool   Add_Res   =true;                 // Add optimization results to filename
extern bool   Add_pr    =true;                 // Add profit to filename
extern bool   Add_tr    =true;                 // Add trades number to filename
extern bool   Add_pf    =false;                // Add profit factor to filename
extern bool   Add_ch    =false;                // Add payoff to filename
extern bool   Add_ddm   =false;                // Add drawdown ($) to filename
extern bool   Add_ddp   =true;                 // Add drawdown (%) to filename
extern bool   Add_ont   =true;                 // Add OnTester result to filename
extern string cap1      ="";                   // Filters:
extern int    MaxDD     =9999999;           

string Str;

void OnStart()
{
int filehandle1, filehandle2;           

filehandle1=FileOpen(FileName+".htm",FILE_READ|FILE_TXT);
FileSeek(filehandle1,0,SEEK_SET);

if(filehandle1!=INVALID_HANDLE)
 while(!FileIsEnding(filehandle1) && !IsStopped()) 
  { 
   Str=FileReadString(filehandle1);
   if(StringFind(Str,"td title=")<0) continue;
   
   string FileNameData=StringSubstr(Str,StringFind(Str,"; \">")+4);
   string filname=FolderName+"//"+prefix+IntegerToString(StrToInteger(FileNameData));
   
   if(Add_Res)
    {
     //22</td><td class=mspt>406316.06</td><td>1745</td><td class=mspt>1.88</td><td class=mspt>232.85</td><td class=mspt>36000.00</td><td class=mspt>26.29</td><td class=mspt>6.32000000</td></tr>
     int pos =StringFind(FileNameData,"</td><td>");
     int post=StringFind(FileNameData,"spt>")+4;
     string Str1=StringSubstr(FileNameData,post,pos-post);
     if(Add_pr) filname=filname+"_pr"+Str1;
     FileNameData=StringSubstr(FileNameData,pos+9);

     post=StringFind(FileNameData,"</td><td class=mspt>");
     Str1=StringSubstr(FileNameData,0,post);
     if(Add_tr) filname=filname+"_tr"+Str1;
     FileNameData=StringSubstr(FileNameData,post+20);
     
     post=StringFind(FileNameData,"</td><td class=mspt>");
     Str1=StringSubstr(FileNameData,0,post);
     if(Add_pf) filname=filname+"_pf"+Str1;
     FileNameData=StringSubstr(FileNameData,post+20);
     
     post=StringFind(FileNameData,"</td><td class=mspt>");
     Str1=StringSubstr(FileNameData,0,post);
     if(Add_ch) filname=filname+"_ch"+Str1;
     FileNameData=StringSubstr(FileNameData,post+20);

     post=StringFind(FileNameData,"</td><td class=mspt>");
     Str1=StringSubstr(FileNameData,0,post);
     if(Add_ddm) filname=filname+"_ddm"+Str1;
     FileNameData=StringSubstr(FileNameData,post+20);
     if(StringToDouble(Str1)>MaxDD) continue;
     
     post=StringFind(FileNameData,"</td><td class=mspt>");
     Str1=StringSubstr(FileNameData,0,post);
     if(Add_ddp) filname=filname+"_ddp"+Str1;
     FileNameData=StringSubstr(FileNameData,post+20);

     if(Add_ont) filname=filname+"_ont"+DoubleToString(StrToDouble(FileNameData),2);
    }
   
   filname=filname+".set";   

   filehandle2=FileOpen(filname,FILE_WRITE|FILE_READ|FILE_TXT);
   
   Str=StringSubstr(Str,StringFind(Str,"<td title=")+11);
   
   while(StringFind(Str,";")>0 && !IsStopped())
    {
     int pos=StringFind(Str,";");
     string Str1=StringSubstr(Str,0,pos);
     FileWriteString(filehandle2,Str1+"\r\n");
     Str=StringSubstr(Str,pos+2);
    }
   
   FileClose(filehandle2);
  }
else Print("Fail to open file. Error ",GetLastError());

FileClose(filehandle1);
}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---