expert_analyze

Author: Viatcheslav Suvorov
Price Data Components
Series array that contains open prices of each bar
Miscellaneous
It writes information to fileUses files from the file systemIt issuies visual alerts to the screenIt reads information from a file
0 Views
0 Downloads
0 Favorites
expert_analyze
#property copyright "Viatcheslav Suvorov"
#property link      "slava_suvorov@list.ru"
#property show_inputs
#define arraysize 193 


string reportname      =   "StrategyTester.htm"; 
string MTpath      =   "D:\Program Files\MetaTrader - North Finance"; 
int price=PRICE_CLOSE;
//int barsbehinde=96;
//int barsafter=96;
double bestprofit=0.3;
double bestloss=0.3;
int Hour_shift=0; 




#include <WinUser32.mqh>
 
#import "mt4excel.dll"
bool  ExcelOpenFile(string FileName);//Îòêðûâàåò ôàéë Excel
bool  ExcelClose();//Çàêðûâàåò Excel
bool  ExcelSetFormula(string Value);//Çàïèñàòü ôîðìóëó â ÿ÷åéêó
bool  ExcelSetRange(string Range);//Çàïîìíèòü äèàïàçîí


bool  ExcelSetValueCell(int X,int Y,double Value);//Çàïèñàòü ÷èñëî â ÿ÷åéêó
bool  ExcelSetTextCell(int X,int Y,string Value);//Çàïèñàòü òåêñò â ÿ÷åéêó
bool ExcelSetDiagramma(int TypeD,string Title,string XRange,string YRange,int Left,int Top,int Riht,int Bottom);//Äîáàâëÿåò äèàãðàìó

string ExcelGetLastErrorText();//Òåêñò ïîñëåäíåé îøèáêè Excel
#import

string results[0][9];

string StringCutAndPaste(string source, string cut, string paste){
   int p=StringFind(source,cut,0);
   if (p==-1) return(source);
   return(StringSubstr(source,0,p)+paste+StringSubstr(source,p+StringLen(cut)));
}//StringCutAndPaste

string IntToA1(int c){
  switch(c){
    case 1: return("A");  break;
    case 2: return("B");  break;
    case 3: return("C");  break;
    case 4: return("D");  break;
    case 5: return("E");  break;
    case 6: return("F");  break;
    case 7: return("G");  break;
    case 8: return("H");  break;
    case 9: return("I");  break;
    case 10: return("J");  break;
    case 11: return("K");  break;
    case 12: return("L");  break;
    case 13: return("M");  break;
    case 14: return("N");  break;
    case 15: return("O");  break;
    case 16: return("P");  break;
    case 17: return("Q");  break;
    case 18: return("R");  break;
    case 19: return("S");  break;
    case 20: return("T");  break;
    case 21: return("U");  break;
    case 22: return("V");  break;
    case 23: return("W");  break;
    case 24: return("X");  break;
    case 25: return("Y");  break;
    case 26: return("Z");  break;
    
  }//switch
}//IntToA1

string R1C1toA1(string r1c1){
   int p=StringFind(r1c1,"C",0);  
   if (p==-1) return("error");
   string c1=StringSubstr(r1c1,p+1);
   string r1=StringSubstr(r1c1,1,p-1);
   int c1int=StrToDouble(c1);
   int c11=MathFloor(c1int/27);
   int c12=c1int-c11*27;
   if (c11>0) c12++;
   return(IntToA1(c11)+IntToA1(c12)+r1); 
}//R1C1toA1


bool WriteStatisticToFile(int h,double data[][]){
   int arrpos=ArrayRange(data,0);    
   int barsbehinde=(arraysize-1)/2;
   int barsafter=(arraysize-1)-barsbehinde;
   
   FileWriteString(h,"Âðåìÿ(ìèí);",StringLen("Âðåìÿ(ìèí);"));
   if (arrpos>0)
     for (int kk=0;kk<arraysize;kk++){               
       string txt=DoubleToStr((kk-barsbehinde)*Period(),0)+";";
       txt=StringCutAndPaste(txt,".",",");
       FileWriteString(h,txt, StringLen(txt)); 
     }//for  
   FileWriteString(h,"\r\n", StringLen("\r\n")); 
   
   FileWriteString(h,"Ñðåäíÿÿ(ïóíêòû);",StringLen("Ñðåäíÿÿ(ïóíêòû);"));
   double mo[arraysize];
   for (int jj=0;jj<arrpos;jj++) 
     for (kk=0;kk<arraysize;kk++)
       mo[kk]=mo[kk]+data[jj,kk];
          
   if (arrpos>0)
     for (kk=0;kk<arraysize;kk++){        
       mo[kk]=mo[kk]/arrpos;
       txt=DoubleToStr(mo[kk],2)+";";
       txt=StringCutAndPaste(txt,".",",");
       FileWriteString(h,txt, StringLen(txt)); 
     }//for  
   FileWriteString(h,"\r\n", StringLen("\r\n")); 

   FileWriteString(h,"ÑÊÎ;",StringLen("ÑÊÎ;"));   
   double sko[arraysize];
   for (jj=0;jj<arrpos;jj++) 
     for (kk=0;kk<arraysize;kk++)
       sko[kk]=sko[kk]+MathSqrt(MathPow(data[jj,kk]-mo[kk],2));

   if (arrpos>0)
     for (kk=0;kk<arraysize;kk++){        
       sko[kk]=sko[kk]/arrpos;
       txt=DoubleToStr(sko[kk],2)+";";
       txt=StringCutAndPaste(txt,".",",");
       FileWriteString(h,txt, StringLen(txt)); 
     }//for  
   FileWriteString(h,"\r\n", StringLen("\r\n")); 


   double sko1[arraysize];
   double sko1count[arraysize];
   for (jj=0;jj<arrpos;jj++) 
     for (kk=0;kk<arraysize;kk++) 
       if (data[jj,kk]>=mo[kk]){  
         sko1count[kk]++;
         sko1[kk]=sko1[kk]+MathSqrt(MathPow(data[jj,kk]-mo[kk],2));
       }//if  

   if (arrpos>0)
     for (kk=0;kk<arraysize;kk++) 
       if (sko1count[kk]>0) sko1[kk]=sko1[kk]/sko1count[kk]; else sko1[kk]=0;
     
   double sko2[arraysize];
   double sko2count[arraysize];
   for (jj=0;jj<arrpos;jj++) 
     for (kk=0;kk<arraysize;kk++) 
       if (data[jj,kk]<mo[kk]){  
         sko2count[kk]++;
         sko2[kk]=sko2[kk]+MathSqrt(MathPow(data[jj,kk]-mo[kk],2));
       }//if  

   if (arrpos>0)
     for (kk=0;kk<arraysize;kk++) 
       if (sko2count[kk]>0) sko2[kk]=sko2[kk]/sko2count[kk]; else sko2[kk]=0;


   FileWriteString(h,"Âåðõíÿÿ ãðàíèöà;",StringLen("Âåðõíÿÿ ãðàíèöà;"));      
   if (arrpos>0)
     for (kk=0;kk<arraysize;kk++){               
       txt=DoubleToStr(mo[kk]+3*sko1[kk],2)+";";
       txt=StringCutAndPaste(txt,".",",");
       FileWriteString(h,txt, StringLen(txt)); 
     }//for  
   FileWriteString(h,"\r\n", StringLen("\r\n")); 

   FileWriteString(h,"Íèæíÿÿ ãðàíèöà;",StringLen("Íèæíÿÿ ãðàíèöà;"));      
   if (arrpos>0)
     for (kk=0;kk<arraysize;kk++){               
       txt=DoubleToStr(mo[kk]-3*sko2[kk],2)+";";
       txt=StringCutAndPaste(txt,".",",");
       FileWriteString(h,txt, StringLen(txt)); 
     }//for  
   FileWriteString(h,"\r\n", StringLen("\r\n")); 
   
}//WriteStatisticToFile

double Profit(int num){  
  for(int all=0;all<ArraySize(results);all++){ //check all entry of one trade
    int curnum=StrToDouble(results[all][3]);
    if(results[all][2]=="s/l" || results[all][2]=="t/p" || results[all][2]=="close" || results[all][2]=="close at stop") 
      if (curnum==num) {
       // Print(results[all][8]);
        return(StrToDouble(results[all][8]));
      }  
  }//for
}//Profit

void start()
{
   int barsbehinde=(arraysize-1)/2;
   int barsafter=(arraysize-1)-barsbehinde;

   double short[][arraysize];
   double long[][arraysize];
  
   bool FlagCont=true;
   string var,piece,value;
   
   int row,begin,end,cnt,cntOrders,all;
   double orders[];
   double stoploss,takeprofit;
   string description,lots;
   
   string ticket; 
   string opentime; 
   string type; 
   double openprice;
   string closetime;
   double closeprice;
   int count=0;
   string name;
 
   
   int handle=FileOpen(reportname,FILE_READ,0x7F);
   if(handle<0)
     {
         Alert("File "+reportname+" does not exist !");
         return;
     }         
   FileSeek(handle,0,SEEK_SET);
   int handle1=FileOpen("enrypoints.csv",FILE_BIN|FILE_WRITE);
   if(handle1<1)
    {
     Print("Íå óäàåòñÿ ñîçäàòü ôàéë enrypoints.csv ïîñëåäíÿÿ îøèáêà ", GetLastError());
     return(false);
    }


   while(FlagCont)
      {
         var=FileReadString(handle);
         piece=StringSubstr(var,29,6);
         if(piece=="Symbol")
            {
               piece=StringSubstr(var,54,6);
               if(piece!=Symbol()) 
                  {
                     Alert("Strategy was testing on ",piece," chart. It is not possible to draw results to ",Symbol()," chart !");
                     return;
                  }
            }           
         piece=StringSubstr(var,0,11);
         if(piece=="<tr bgcolor") FlagCont=false;
      }

   
   
   while(FileIsEnding(handle)==false)
      {
         while (FileIsLineEnding(handle)) 
            {
               ArrayResize(results,row+1);
               
               var=FileReadString(handle);
               if(var=="") break;
               begin=StringFind(var, "<td>",0)+4;                             //Position of action
               end=StringFind(var, "</td>",begin);                            //Find the end of position
               value = StringSubstr(var, begin, end-begin);                   //Read the value
               results[row][0]= value;                                        //number of action
               //-----------------
               begin=StringFind(var, "date>",end)+5;                          //Find the beginning of the position
               end=StringFind(var, "</td>",begin);                            //Find the end of position
               value = StringSubstr(var, begin, end-begin);                   //Read the value
               results[row][1]= value;                                        //time of action
               //-----------------
               begin=StringFind(var, "<td>",end)+4;                           //Find the beginning of the position
               end=StringFind(var, "</td>",begin);                            //Find the end of position
               value = StringSubstr(var, begin, end-begin);                   //Read the value
               results[row][2]= value;                                        //type of action
               //-----------------
               begin=StringFind(var, "<td>",end)+4;                           //Find the beginning of the position 
               end=StringFind(var, "</td>",begin);                            //Find the end of position
               value = StringSubstr(var, begin, end-begin);                   //Read the value
               results[row][3]= value;                                        //order's number 
               //-----------------
               begin=StringFind(var, "mspt>",end)+5;                          //Find the beginning of the position
               end=StringFind(var, "</td>",begin);                            //Find the end of position
               value = StringSubstr(var, begin, end-begin);                   //Read the value
               results[row][4]= value;                                        //lot size
               //-----------------
               if(Digits==4) begin=StringFind(var, "0\.0000;",end)+10;         //Find the beginning of the position
               else begin=StringFind(var, "0\.00;",end)+8;
               end=StringFind(var, "</td>",begin);                            //Find the end of position
               value = StringSubstr(var, begin, end-begin);                   //Read the value
               results[row][5]= value;                                        //open price
               //-----------------
               begin=StringFind(var, "right>",end)+6;                         //Find the beginning of the position 
               end=StringFind(var, "</td>",begin);                            //Find the end of position
               value = StringSubstr(var, begin, end-begin);                   //Read the value
               results[row][6]= value;                                        //stoploss
               //-----------------
               begin=StringFind(var, "right>",end)+6;                         //Find the beginning of the position
               end=StringFind(var, "</td>",begin);                            //Find the end of position
               value = StringSubstr(var, begin, end-begin);                   //Read the value
               results[row][7]= value;                                        //take profit
               //-----------------
               begin=StringFind(var, "mspt>",end)+5;                          //Find the beginning of the position
               end=StringFind(var, "</td>",begin);                            //Find the end of position
               value = StringSubstr(var, begin, end-begin);                   //Read the value
               results[row][8]= value;                                        //profit size
               
               row++;
            }
         break;  
      }  
               
   Comment("First trade opened - ",results[0][1], "  last trade closed - ",results[row-1][1]);
   for(cnt=1;cnt<=row;cnt++) 
      {
         ArrayResize(orders,cnt);         
         orders[cnt-1]=StrToInteger(results[cnt-1][3]);
      }   
   cntOrders=orders[ArrayMaximum(orders)];
      
      
   int totalShort;   
   FileWriteString(handle1,"Âñå Long\r\n", StringLen("Âñå Long\r\n")); 
   for(cnt=1;cnt<=cntOrders;cnt++) // check all trades
      {         
         for(all=0;all<ArraySize(results);all++) //check all entry of one trade
            {
               if(cnt!=StrToInteger(results[all][3])) continue;               
               if(results[all][2]=="buy") 
                  {
                     type=results[all][2];
                     opentime=results[all][1];
                     lots=results[all][4]; 
                     openprice=StrToDouble(results[all][5]);                                 
                     ticket=cnt;
                     stoploss=StrToDouble(results[all][6]); 
                     takeprofit=StrToDouble(results[all][7]);
                     description=StringConcatenate("#",ticket," lots:",lots," time:",opentime," SL:",results[all][6]," TP:",results[all][7]);
                     
                     name="Open trade - Object Nr. "+DoubleToStr(count,0);
                     count++;   

                     int position=iBarShift(NULL,0,StrToTime(opentime)+Hour_shift*3600);
                     int startcykle=position+barsbehinde;

                     int endcykle=position-barsafter;
                     totalShort++;
                     
                     int arrpos=totalShort;
                     ArrayResize(long,arrpos+1);
                                          
                     for (int jj=startcykle;jj>=endcykle;jj--)
                       if (jj==position)
                     //    FileWriteString(handle1, "0;", 2); 
                         long[arrpos,jj-startcykle]=0;                     
                       else {   
                         int val=(iOpen(NULL,0,jj)-openprice)/Point;                    
                         long[arrpos,startcykle-jj]=val;
                       }//if                       
                  }
                  

/*               if(results[all][2]=="s/l" || results[all][2]=="t/p" || results[all][2]=="close" || results[all][2]=="close at stop")
                  {
                     closetime=results[all][1];
                     closeprice=StrToDouble(results[all][5]);
                     
                     name="Close trade - Object Nr. "+DoubleToStr(count,0);
                     count++;
              
                     ObjectCreate(name, OBJ_ARROW, 0, StrToTime(closetime)+Hour_shift*3600, closeprice);  
                     ObjectSet(name, OBJPROP_ARROWCODE, 242);        
                     if(type=="buy")ObjectSet(name, OBJPROP_COLOR, Aqua);
                     else ObjectSet(name, OBJPROP_COLOR, Tomato);
                     ObjectSetText(name, description,10,"Arial", Blue);
       
                     name="Connection - Object Nr. "+DoubleToStr(count,0);
                     count++;
       
                     ObjectCreate(name, OBJ_TREND, 0, StrToTime(opentime)+Hour_shift*3600, openprice,StrToTime(closetime), closeprice);  
                     ObjectSet(name, OBJPROP_RAY, false); 
                     ObjectSet(name, OBJPROP_STYLE, STYLE_DOT); 
                     if(type=="buy")ObjectSet(name, OBJPROP_COLOR, Aqua);
                     else ObjectSet(name, OBJPROP_COLOR, Tomato);
                     ObjectSetText(name, StringConcatenate("#",ticket,"   ",openprice," --> ",closeprice),10,"Arial", Blue);          
                  } 
                  
                  
               if(results[all][2]=="modify")
                  {
                     name="Modify SL - Object Nr. "+DoubleToStr(count,0);
                     count++;
       
                     ObjectCreate(name, OBJ_TREND, 0, StrToTime(opentime)+Hour_shift*3600, StrToDouble(results[all][6]),StrToTime(opentime)+Period()*60, StrToDouble(results[all][6]));  
                     ObjectSet(name, OBJPROP_RAY, false); 
                     ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID); 
                     if(type=="buy")ObjectSet(name, OBJPROP_COLOR, Teal);
                     else ObjectSet(name, OBJPROP_COLOR, YellowGreen);
                     ObjectSetText(name, StringConcatenate("#",ticket," modify SL"),10,"Arial", Blue);          

                     name="Modify TP- Object Nr. "+DoubleToStr(count,0);
                     count++;
       
                     ObjectCreate(name, OBJ_TREND, 0, StrToTime(opentime)+Hour_shift*3600, StrToDouble(results[all][7]),StrToTime(opentime)+Period()*60, StrToDouble(results[all][7]));  
                     ObjectSet(name, OBJPROP_RAY, false); 
                     ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID); 
                     if(type=="buy")ObjectSet(name, OBJPROP_COLOR, OrangeRed);
                     else ObjectSet(name, OBJPROP_COLOR, Peru);
                     ObjectSetText(name, StringConcatenate("#",ticket," modify TP"),10,"Arial", Blue);          
                     
                  }
                  */
             } // end -check all entry of one trade
      }   //end -  check all trades            
   WriteStatisticToFile(handle1,long);
        
   int totalLong;   
   FileWriteString(handle1,"Âñå Short\r\n", StringLen("Âñå Short\r\n")); 
   for(cnt=1;cnt<=cntOrders;cnt++) // check all trades
      {         
         for(all=0;all<ArraySize(results);all++) //check all entry of one trade
            {
               if(cnt!=StrToInteger(results[all][3])) continue;               
               if(results[all][2]=="sell") 
                  {
                     type=results[all][2];
                     opentime=results[all][1];
                     lots=results[all][4]; 
                     openprice=StrToDouble(results[all][5]);                                 
                     ticket=cnt;
                     stoploss=StrToDouble(results[all][6]); 
                     takeprofit=StrToDouble(results[all][7]);
                     description=StringConcatenate("#",ticket," lots:",lots," time:",opentime," SL:",results[all][6]," TP:",results[all][7]);
                     
                     name="Open trade - Object Nr. "+DoubleToStr(count,0);
                     count++;
                     

                     position=iBarShift(NULL,0,StrToTime(opentime)+Hour_shift*3600);
                     startcykle=position+barsbehinde;
                     endcykle=position-barsafter;
                     
                     totalLong++;                          
                     arrpos=totalLong;
                     ArrayResize(short,arrpos+1);
                     
                     
                     for (jj=startcykle;jj>=endcykle;jj--)
                       if (jj==position)
                         short[arrpos,jj-startcykle]=0;                     
                       else {       
                         val=(iOpen(NULL,0,jj)-openprice)/Point;                    
                         short[arrpos,startcykle-jj]=val;
                       }//if

                  }//if


             } // end -check all entry of one trade
      }   //end -  check all trades            
   WriteStatisticToFile(handle1,short);

   totalShort=0;   
   FileWriteString(handle1,"Ïðèáûëüíûå Long\r\n", StringLen("Ïðèáûëüíûå Long\r\n")); 
   for(cnt=1;cnt<=cntOrders;cnt++) // check all trades
      {         
         for(all=0;all<ArraySize(results);all++) //check all entry of one trade
            {
               if(cnt!=StrToInteger(results[all][3])) continue;            
               //if(results[all][2]=="buy") Print("¹=",results[all][3]);
               if((results[all][2]=="buy") && (Profit(StrToDouble(results[all][3]))>0)) 
                  {
                     type=results[all][2];
                     opentime=results[all][1];
                     lots=results[all][4]; 
                     openprice=StrToDouble(results[all][5]);                                 
                     ticket=cnt;
                     stoploss=StrToDouble(results[all][6]); 
                     takeprofit=StrToDouble(results[all][7]);
                     description=StringConcatenate("#",ticket," lots:",lots," time:",opentime," SL:",results[all][6]," TP:",results[all][7]);
                     
                     name="Open trade - Object Nr. "+DoubleToStr(count,0);
                     count++;   

                     position=iBarShift(NULL,0,StrToTime(opentime)+Hour_shift*3600);
                     startcykle=position+barsbehinde;

                     endcykle=position-barsafter;
                     totalShort++;
                     
                     arrpos=totalShort;
                     ArrayResize(long,arrpos+1);
                                          
                     for (jj=startcykle;jj>=endcykle;jj--)
                       if (jj==position)
                         long[arrpos,jj-startcykle]=0;                     
                       else {   
                         val=(iOpen(NULL,0,jj)-openprice)/Point;                    
                         long[arrpos,startcykle-jj]=val;
                       }//if                       
                  }
             } // end -check all entry of one trade
      }   //end -  check all trades            
   WriteStatisticToFile(handle1,long);

   totalLong=0;   
   FileWriteString(handle1,"Ïðèáûëüíûå Short\r\n", StringLen("Ïðèáûëüíûå Short\r\n")); 
   for(cnt=1;cnt<=cntOrders;cnt++) // check all trades
      {         
         for(all=0;all<ArraySize(results);all++) //check all entry of one trade
            {
               if(cnt!=StrToInteger(results[all][3])) continue;               
               if((results[all][2]=="sell") && (Profit(StrToDouble(results[all][3]))>0))
                  {
                     type=results[all][2];
                     opentime=results[all][1];
                     lots=results[all][4]; 
                     openprice=StrToDouble(results[all][5]);                                 
                     ticket=cnt;
                     stoploss=StrToDouble(results[all][6]); 
                     takeprofit=StrToDouble(results[all][7]);
                     description=StringConcatenate("#",ticket," lots:",lots," time:",opentime," SL:",results[all][6]," TP:",results[all][7]);
                     
                     name="Open trade - Object Nr. "+DoubleToStr(count,0);
                     count++;
                     

                     position=iBarShift(NULL,0,StrToTime(opentime)+Hour_shift*3600);
                     startcykle=position+barsbehinde;
                     endcykle=position-barsafter;
                     
                     totalLong++;                          
                     arrpos=totalLong;
                     ArrayResize(short,arrpos+1);
                     
                     
                     for (jj=startcykle;jj>=endcykle;jj--)
                       if (jj==position)
                         short[arrpos,jj-startcykle]=0;                     
                       else {       
                         val=(iOpen(NULL,0,jj)-openprice)/Point;                    
                         short[arrpos,startcykle-jj]=val;
                       }//if

                  }//if


             } // end -check all entry of one trade
      }   //end -  check all trades            
   WriteStatisticToFile(handle1,short);

   totalShort=0;   
   FileWriteString(handle1,"Óáûòî÷íûå Long\r\n", StringLen("Óáûòî÷íûå Long\r\n")); 
   for(cnt=1;cnt<=cntOrders;cnt++) // check all trades
      {         
         for(all=0;all<ArraySize(results);all++) //check all entry of one trade
            {
               if(cnt!=StrToInteger(results[all][3])) continue;                         
               if((results[all][2]=="buy") && (Profit(StrToDouble(results[all][3]))<0)) 
                  {
                     type=results[all][2];
                     opentime=results[all][1];
                     lots=results[all][4]; 
                     openprice=StrToDouble(results[all][5]);                                 
                     ticket=cnt;
                     stoploss=StrToDouble(results[all][6]); 
                     takeprofit=StrToDouble(results[all][7]);
                     description=StringConcatenate("#",ticket," lots:",lots," time:",opentime," SL:",results[all][6]," TP:",results[all][7]);
                     
                     name="Open trade - Object Nr. "+DoubleToStr(count,0);
                     count++;   

                     position=iBarShift(NULL,0,StrToTime(opentime)+Hour_shift*3600);
                     startcykle=position+barsbehinde;

                     endcykle=position-barsafter;
                     totalShort++;
                     
                     arrpos=totalShort;
                     ArrayResize(long,arrpos+1);
                                          
                     for (jj=startcykle;jj>=endcykle;jj--)
                       if (jj==position)
                         long[arrpos,jj-startcykle]=0;                     
                       else {   
                         val=(iOpen(NULL,0,jj)-openprice)/Point;                    
                         long[arrpos,startcykle-jj]=val;
                       }//if                       
                  }
             } // end -check all entry of one trade
      }   //end -  check all trades            
   WriteStatisticToFile(handle1,long);

   totalLong=0;   
   FileWriteString(handle1,"Óáûòî÷íûå Short\r\n", StringLen("Óáûòî÷íûå Short\r\n")); 
   for(cnt=1;cnt<=cntOrders;cnt++) // check all trades
      {         
         for(all=0;all<ArraySize(results);all++) //check all entry of one trade
            {
               if(cnt!=StrToInteger(results[all][3])) continue;               
               if((results[all][2]=="sell") && (Profit(StrToDouble(results[all][3]))<0))
                  {
                     type=results[all][2];
                     opentime=results[all][1];
                     lots=results[all][4]; 
                     openprice=StrToDouble(results[all][5]);                                 
                     ticket=cnt;
                     stoploss=StrToDouble(results[all][6]); 
                     takeprofit=StrToDouble(results[all][7]);
                     description=StringConcatenate("#",ticket," lots:",lots," time:",opentime," SL:",results[all][6]," TP:",results[all][7]);
                     
                     name="Open trade - Object Nr. "+DoubleToStr(count,0);
                     count++;
                     

                     position=iBarShift(NULL,0,StrToTime(opentime)+Hour_shift*3600);
                     startcykle=position+barsbehinde;
                     endcykle=position-barsafter;
                     
                     totalLong++;                          
                     arrpos=totalLong;
                     ArrayResize(short,arrpos+1);
                     
                     
                     for (jj=startcykle;jj>=endcykle;jj--)
                       if (jj==position)
                         short[arrpos,jj-startcykle]=0;                     
                       else {       
                         val=(iOpen(NULL,0,jj)-openprice)/Point;                    
                         short[arrpos,startcykle-jj]=val;
                       }//if

                  }//if


             } // end -check all entry of one trade
      }   //end -  check all trades            
   WriteStatisticToFile(handle1,short);
      
   FileClose(handle);
   FileClose(handle1);
   if (ExcelOpenFile(MTpath+"\experts\files\enrypoints.csv")) Print("Ócïåøíî îòêðûëè Excel"); else Print("Íå îòêðûâàåòñÿ Excel:",ExcelGetLastErrorText());//Îòêðûâàåì Excel  

   ExcelSetDiagramma(88,"Òðåéäû ëîíã, ðàçâåðòêà ïî âðåìåíè",R1C1toA1("R2C2")+":"+R1C1toA1("R2C194"),R1C1toA1("R3C2")+":"+R1C1toA1("R3C194")+";"+R1C1toA1("R5C2")+":"+R1C1toA1("R6C194"),0,0,400,200);  
   ExcelSetDiagramma(88,"Òðåéäû øîðò, ðàçâåðòêà ïî âðåìåíè",R1C1toA1("R8C2")+":"+R1C1toA1("R8C194"),R1C1toA1("R9C2")+":"+R1C1toA1("R9C194")+";"+R1C1toA1("R11C2")+":"+R1C1toA1("R12C194"),400,0,400,200);  
   ExcelSetDiagramma(88,"Ïðèáûëüíûå òðåéäû ëîíã, ðàçâåðòêà ïî âðåìåíè",R1C1toA1("R14C2")+":"+R1C1toA1("R14C194"),R1C1toA1("R15C2")+":"+R1C1toA1("R15C194")+";"+R1C1toA1("R17C2")+":"+R1C1toA1("R18C194"),0,200,400,200);  
   ExcelSetDiagramma(88,"Ïðèáûëüíûå òðåéäû øîðò, ðàçâåðòêà ïî âðåìåíè",R1C1toA1("R20C2")+":"+R1C1toA1("R20C194"),R1C1toA1("R21C2")+":"+R1C1toA1("R21C194")+";"+R1C1toA1("R23C2")+":"+R1C1toA1("R24C194"),400,200,400,200);
   ExcelSetDiagramma(88,"Óáûòî÷íûå òðåéäû ëîíã, ðàçâåðòêà ïî âðåìåíè",R1C1toA1("R26C2")+":"+R1C1toA1("R26C194"),R1C1toA1("R27C2")+":"+R1C1toA1("R27C194")+";"+R1C1toA1("R29C2")+":"+R1C1toA1("R30C194"),0,400,400,200);   
   ExcelSetDiagramma(88,"Óáûòî÷íûå òðåéäû øîðò, ðàçâåðòêà ïî âðåìåíè",R1C1toA1("R32C2")+":"+R1C1toA1("R32C194"),R1C1toA1("R33C2")+":"+R1C1toA1("R33C194")+";"+R1C1toA1("R35C2")+":"+R1C1toA1("R36C194"),400,400,400,200); 
   Print(ExcelGetLastErrorText());  

}






Comments