Please help, a little advice. I can not find the error ....
I read the "optimization report" (file htm) of metatrader end I'm trying to export the value in a file csv, but i have this result:
The second row is wrong (A2:H2) and the ProficFactor (C2:C6) is wrong (the rest i correct). The record of the htm report are 4.
This is the code:
....
file=FileOpen(FileReport,FILE_READ,0x7F) ;
....
while(FileIsEnding(file)==false) //thus far did not begin the end of the file - cycle
{
FileLine=FileReadString(file); //let us read line from the file of the report
index=StringFind(FileLine, "title", 20); //let us find necessary line and will establish starting pointif(index>0)
{
ArrayResize(ArrayStrg,NumStr+1); //we increase the size of the massif
ArrayStrg[NumStr]=FileLine; //we write into the massif of line from the filePrint ("FileLine",FileLine);
NumStr++;
}
}
FileClose(file); //let us shut the file//FileDelete(FileReport); //let us remove file in order not to procreate the copyArrayResize(ArrayData,NumStr); //let us establish the size of massif in a quantity of the counted from the file linesfor(text=0;text<NumStr;text++)
{
select=ArrayStrg[text];
//-------------------------------------------------------------------------// Working the text of the report (we separate flies from the cutlets) //---------------------position is the passage------------------------------
ClStep=StringFind(select, "; \">",20)+4; //let us find the beginning of the position
ClStepRazm=StringFind(select, "</td>",ClStep); //let us find the end of the position
CycleStep = StringSubstr(select, ClStep, ClStepRazm-ClStep); //we count the sum//---------------- Ïîçèöèÿ Ïðèáûëü -------------------------------
GrProf=StringFind(select,"<td class=mspt>",ClStepRazm); //let us find the beginning of the position
GrProfRazm=StringFind(select, "</td>",GrProf); //let us find the end of the position
GrossProfit = StringSubstr(select, GrProf+15,GrProfRazm-(GrProf+15)); //we count the sum//-------------Ïîçèöèÿ Âñåãî Ñäåëîê -----------------------------
TotTrad=StringFind(select, "<td>",GrProfRazm); //let us find the beginning of the position
TotTradRazm=StringFind(select, "</td>",TotTrad); //let us find the end of the position
TotalTrades = StringSubstr(select, TotTrad+4,TotTradRazm-(TotTrad+4)); //we count the sum//-------------Ïîçèöèÿ Ïðèáûëüíîñòü--------------------------------
ProfFact=StringFind(select, "<td class=mspt>",TotTradRazm); //let us find the beginning of the position
ProfFactRazm=StringFind(select, "</td>",ProfFact); //let us find the end of the position
ProfitFactor = StringSubstr(select, ProfFact+15,ProfFactRazm-(ProfFact+15)); //we count the sum//-------------Ïîçèöèÿ Ìàò Îæèäàíèå---------------------------------
ExpPay=StringFind(select, "<td class=mspt>",ProfFactRazm); //let us find the beginning of the position
ExpPayRazm=StringFind(select, "</td>",ExpPay); //let us find the end of the position
ExpectedPayoff = StringSubstr(select, ExpPay+15,ExpPayRazm-(ExpPay+15)); //we count the sum//------------------------------------------------------------------Print ("select",select);
Print (ClStep+"-"+ClStepRazm+"-"+CycleStep);
Print (GrProf+"-"+GrProfRazm+"-"+GrossProfit);
Print (TotTrad+"-"+TotTradRazm+"-"+TotalTrades);
Print (ProfFact+"-"+ProfFactRazm+"-"+ProfitFactor);
Print (ExpPay+"-"+ExpPayRazm+"-"+ExpectedPayoff);
//-------------Ïîçèöèè ïåðåìåííûõ----------------------------------------// P1=StringFind(select, Per1,20); //let us find the beginning of the position
P1=StringFind(select, Per1,20); //let us find the beginning of the position
P1k=StringFind(select, ";",P1); //let us find the end of the position
Perem1 = StringSubstr(select,P1+StringLen(Per1)+1,P1k-(P1+1+StringLen(Per1))); //we count the variable
P2=StringFind(select, Per2,20); //let us find the beginning of the position
P2k=StringFind(select, ";",P2); //let us find the end of the position
Perem2 = StringSubstr(select,P2+StringLen(Per2)+1,P2k-(P2+1+StringLen(Per2))); //we count the variable
P3=StringFind(select, Per3,20); //let us find the beginning of the position
P3k=StringFind(select, ";",P3); //let us find the end of the position
Perem3 = StringSubstr(select,P3+StringLen(Per3)+1,P3k-(P3+1+StringLen(Per3))); //we count the variable
P4=StringFind(select, Per4,20); //let us find the beginning of the position
P4k=StringFind(select, ";",P4); //let us find the end of the position
Perem4 = StringSubstr(select,P4+StringLen(Per4)+1,P4k-(P4+1+StringLen(Per4))); //we count the variable//-----------------------let us transfer into the numerical size----------------------------
TotalTradesTransit=StrToDouble(TotalTrades);
GrossProfitTransit=NormalizeDouble(StrToDouble(GrossProfit),0);
ExpectedPayoffTran=NormalizeDouble(StrToDouble(ExpectedPayoff),2);
nodubl=true;
if(MinTr < TotalTradesTransit && MaxTr > TotalTradesTransit){ // Filter by the amount of trades
PrFactDouble = NormalizeDouble(StrToDouble(ProfitFactor),2);
if(PrFactDouble==0){PrFactDouble=1000;} //Replace 0 in the AOP_Profit_Factor for proper analysis//-------------- Filter data having identical values ------------------- for(Dubl=0;Dubl<=text;Dubl++)
{ //Start the loop searching for identical valuesif(GrossProfitTransit == ArrayData[Dubl][1])
{ //check whether the results for maximal profit coincideif(TotalTradesTransit == ArrayData[Dubl][2])
{ //check whether the results for the amount of trades coincideif(PrFactDouble == ArrayData[Dubl][3])
{ //check whether the results for Profit Factor coincideif(ExpectedPayoffTran == ArrayData[Dubl][4])
{ //check whether the results for expected payoff coincide//nodubl=false; // If everything coincides, flag it as coincided
}
}
}
}
}
}
//---------------- Write the filtered data in the array ----------------------if(nodubl)
{
ArrayData_TXT[ResizeArayNew][1]=DoubleToStr(GrossProfitTransit,2);
ArrayData_TXT[ResizeArayNew][2]=DoubleToStr(TotalTradesTransit,0);
ArrayData_TXT[ResizeArayNew][3]=DoubleToStr(PrFactDouble,2);
ArrayData_TXT[ResizeArayNew][4]=DoubleToStr(ExpectedPayoffTran,2);
ArrayData_TXT[ResizeArayNew][5]=Perem1;
ArrayData_TXT[ResizeArayNew][6]=Perem2;
ArrayData_TXT[ResizeArayNew][7]=Perem3;
ArrayData_TXT[ResizeArayNew][8]=Perem4;
ArrayData_TXT[ResizeArayNew][9]= TimeToStr(DT_INI_P,TIME_DATE)+"-"+TimeToStr(DT_FINE_P,TIME_DATE) ;
ResizeArayNew++;
}
//---------------- FIN Write the filtered data in the array TEXT----------------------
}
//||||||||||||||||||||||||||||||| write variables into a intermediate file |||||||||||||||||||||||||||||||||||| int FileTst;
string trs1,trs2,trs3,trs6,trs7,trs8,trs9,trs4,trs5, trs10;
string File.csv=FileReport+".csv";
FileTst=FileOpen(File.csv,FILE_CSV|FILE_WRITE,0x7F); //open a file according to notesFileWrite(FileTst,"GrossProfit ; TotalTrades ; ProfitFactor ; ExpectedPayoff ;"+Per1+";"+Per2+";"+Per3+";"+Per4+";"+"Periodo");
if(FileTst>0){
for(i=0; i<ResizeArayNew; i++){
trs2 = ArrayData_TXT[i][1];
trs3 = ArrayData_TXT[i][2];
trs4 = ArrayData_TXT[i][3];
trs5 = ArrayData_TXT[i][4];
trs6 = ArrayData_TXT[i][5];
trs7 = ArrayData_TXT[i][6];
trs8 = ArrayData_TXT[i][7];
trs9 = ArrayData_TXT[i][8];
trs10 = ArrayData_TXT[i][9];
FileWrite(FileTst,trs2+";"+trs3+";"+trs4+";"+trs5+";"+trs6+";"+trs7+";"+trs8+";"+trs9+";"+trs10); //èç ïåðåìåííîé â ôàéë
}
FileClose(FileTst); //Close the file
}
if(FileTst<0){Print("5: KO write" + File.csv);} else {Print ("4: OK write "+File.csv);}
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||GlobalVariableSet( "Opt_step", 0.0);
Print ("Opt_step: ",Glob);
} //the end of the function
The problem clearly lies in the constrution of the output data array especially the first row of the array. So either a StringFind() is failing or the first parameter of the array construction is wrong. Those are the first thoughts on the problem
Yes, i think the problem is in the constution of the first row of the array.
I have insert a print in this cycle of while:
while(FileIsEnding(file)==false) //thus far did not begin the end of the file - cycle
{
FileLine=FileReadString(file); //let us read line from the file of the report
index=StringFind(FileLine, "title", 20); //let us find necessary line and will establish starting pointif(index>0)
{
ArrayResize(ArrayStrg,NumStr+1); //we increase the size of the massif
ArrayStrg[NumStr]=FileLine; //we write into the massif of line from the filePrint ("FileLine",FileLine);
NumStr++;
}
}
While it is not necessarily a good idea to be fixing the code for a particular case I would as a 'quick fix' read the first line to 'throw it away' thus
file=FileOpen(FileReport,FILE_READ,0x7F) ;
....
FileLine=FileReadString(file); //<<<<<< added this read line to remove the first linewhile(FileIsEnding(file)==false) //thus far did not begin the end of the file - cycle
{
FileLine=FileReadString(file); //let us read line from the file of the report
index=StringFind(FileLine, "title", 20); //let us find necessary line and will establish starting pointif(index>0)
{
ArrayResize(ArrayStrg,NumStr+1); //we increase the size of the massif
ArrayStrg[NumStr]=FileLine; //we write into the massif of line from the filePrint ("FileLine",FileLine);
NumStr++;
}
}
FileClose(file); //let us shut the file
Please help, a little advice. I can not find the error ....
I read the "optimization report" (file htm) of metatrader end I'm trying to export the value in a file csv, but i have this result:
The second row is wrong (A2:H2) and the ProficFactor (C2:C6) is wrong (the rest i correct). The record of the htm report are 4.
This is the code:
This is a part of log
(thank's you)
The problem clearly lies in the constrution of the output data array especially the first row of the array. So either a StringFind() is failing or the first parameter of the array construction is wrong. Those are the first thoughts on the problem
To track it dow I would be looking at
And where these lines are called from.
That is as far as I can go at the moment
Thank's Ickyrus.
Yes, i think the problem is in the constution of the first row of the array.
I have insert a print in this cycle of while:
i have this in the log:
But, i don't konw how to remove the problem from the first row ( <title>Strategy Tester: MACD Sample_1</title>) ....While it is not necessarily a good idea to be fixing the code for a particular case I would as a 'quick fix' read the first line to 'throw it away' thus