MT5 can't find string.

 

I have a function I'm trying to convert to MQL5 from MQL4, it works perfectly in MQL4 but MQL5 for some reason breaks without finding the string. The complier shows no errors, I think something is wrong with one of the strings. I attached the file I'm trying to read as txt as well. Any help would be greatly appreciated.

Where it breaks:

void ReadNews()
  {
//--- get today time
   TimeOfDay=(int)TimeCurrent()%86400;
   Midnight=TimeCurrent()-TimeOfDay;
//--- set xml file name ffcal_week_this (fixed name)
   xmlFileName="ff_calendar_thisweek.xml";
//--- checks the existence of the file.
   xmlRead();
//--- define the XML Tags, Vars
   string sTags[7]= {"<title>","<country>","<date><![CDATA[","<time><![CDATA[","<impact><![CDATA[","<forecast><![CDATA[","<previous><![CDATA["};
   string eTags[7]= {"</title>","</country>","]]></date>","]]></time>","]]></impact>","]]></forecast>","]]></previous>"};
   int index=0;
   int next=-1;
   int BoEvent=0,begin=0,end=0;
   string myEvent="";
//--- Minutes calculation
//--- split the currencies into the two parts
   string MainSymbol=StringSubstr(Symbol(),0,3);
   string SecondSymbol=StringSubstr(Symbol(),3,3);
//--- loop to get the data from xml tags
   while(true)
     {
      BoEvent=StringFind(sData,"<event>",BoEvent); 
      if(BoEvent==-1)
         break;


Full function:

void ReadNews()
  {
//--- get today time
   TimeOfDay=(int)TimeCurrent()%86400;
   Midnight=TimeCurrent()-TimeOfDay;
//--- set xml file name ffcal_week_this (fixed name)
   xmlFileName="ff_calendar_thisweek.xml";
//--- checks the existence of the file.
   xmlRead();
//--- define the XML Tags, Vars
   string sTags[7]= {"<title>","<country>","<date><![CDATA[","<time><![CDATA[","<impact><![CDATA[","<forecast><![CDATA[","<previous><![CDATA["};
   string eTags[7]= {"</title>","</country>","]]></date>","]]></time>","]]></impact>","]]></forecast>","]]></previous>"};
   int index=0;
   int next=-1;
   int BoEvent=0,begin=0,end=0;
   string myEvent="";
//--- Minutes calculation
//--- split the currencies into the two parts
   string MainSymbol=StringSubstr(Symbol(),0,3);
   string SecondSymbol=StringSubstr(Symbol(),3,3);
//--- loop to get the data from xml tags
   while(true)
     {
      BoEvent=StringFind(sData,"<event>",BoEvent); 
      if(BoEvent==-1)
         break;
      BoEvent+=7;
      next=StringFind(sData,"</event>",BoEvent);
      if(next == -1)
         break;
      myEvent = StringSubstr(sData,BoEvent,next-BoEvent);
      BoEvent = next;
      begin=0;
      for(int i=0; i<7; i++)
        {
         Event[index][i]="";
         next=StringFind(myEvent,sTags[i],begin);
         //--- Within this event, if tag not found, then it must be missing; skip it
         if(next==-1)
            continue;
         else
           {
            //--- We must have found the sTag okay...
            //--- Advance past the start tag
            begin=next+StringLen(sTags[i]);
            end=StringFind(myEvent,eTags[i],begin);
            //---Find start of end tag and Get data between start and end tag
            if(end>begin && end!=-1)
               Event[index][i]=StringSubstr(myEvent,begin,end-begin);
           }
        }
       if(ReportActive && MainSymbol!=Event[index][COUNTRY] && SecondSymbol!=Event[index][COUNTRY])
         continue;
      if(!IsCountry(Event[index][COUNTRY]))
         continue;
      if(!IncludeHigh && Event[index][IMPACT]=="High")
         continue;
      if(!IncludeMedium && Event[index][IMPACT]=="Medium")
         continue;
      if(!IncludeLow && Event[index][IMPACT]=="Low")
         continue;
      if(!IncludeSpeaks && StringFind(Event[index][TITLE],"Speaks")!=-1)
         continue;
      if(!IncludeHolidays && Event[index][IMPACT]=="Holiday")
         continue;
      if(Event[index][TIME]=="All Day" ||
         Event[index][TIME]=="Tentative" ||
         Event[index][TIME]=="")
         continue;
      if(FindKeyword!="")
        {
         if(StringFind(Event[index][TITLE],FindKeyword)==-1)
            continue;
        }
      if(IgnoreKeyword!="")
        {
         if(StringFind(Event[index][TITLE],IgnoreKeyword)!=-1)
            continue;
        }
      //--- sometimes they forget to remove the tags :)
      if(StringFind(Event[index][TITLE],"<![CDATA[")!=-1)
         StringReplace(Event[index][TITLE],"<![CDATA[","");
      if(StringFind(Event[index][TITLE],"]]>")!=-1)
         StringReplace(Event[index][TITLE],"]]>","");
      if(StringFind(Event[index][TITLE],"]]>")!=-1)
         StringReplace(Event[index][TITLE],"]]>","");
      //---
      if(StringFind(Event[index][FORECAST],"&lt;")!=-1)
         StringReplace(Event[index][FORECAST],"&lt;","");
      if(StringFind(Event[index][PREVIOUS],"&lt;")!=-1)
         StringReplace(Event[index][PREVIOUS],"&lt;","");
      //--- set some values (dashes) if empty
      if(Event[index][FORECAST]=="")
         Event[index][FORECAST]="---";
      if(Event[index][PREVIOUS]=="")
         Event[index][PREVIOUS]="---";
      EventTime1=datetime(MakeDateTime(Event[index][DATE],Event[index][TIME]));
      if(EventTime1>TimeGMT()-60)
         break;
      if(EventTime1<=TimeGMT()-60)
         EventTime1=0;
      index++;
     }
  }
Files:
 
Jesse Phipps:

I have a function I'm trying to convert to MQL5 from MQL4, it works perfectly in MQL4 but MQL5 for some reason breaks without finding the string. The complier shows no errors, I think something is wrong with one of the strings. I attached the file I'm trying to read as txt as well. Any help would be greatly appreciated.

Where it breaks:


Full function:

has sdata loaded ?

try this funion also if it says cannot open fle check file permissions , if you are sent the file and not downloading it

#property version   "1.00"
int OnInit()
  {
  EventSetMillisecondTimer(44); 
   return(INIT_SUCCEEDED);
  }
void OnTimer(){
EventKillTimer();
string longstring="";
    uchar bytes[];
    int f=FileOpen("ff_calendar_thisweek.txt",FILE_READ|FILE_BIN);
    if(f!=INVALID_HANDLE){
    Print("Opened , file size "+FileSize(f));
    ArrayResize(bytes,(int)FileSize(f),0);
    FileReadArray(f,bytes,0,ArraySize(bytes));
    FileClose(f);
    longstring=CharArrayToString(bytes,0,ArraySize(bytes),CP_ACP);
    }else{
    Print("Cannot open file");
    }
Print("Size of data "+StringLen(longstring));
int eveid=StringFind(longstring,"<event>",0);
if(eveid!=-1){
  Print("Found event");
  }else{
  Print("Cant find event");
  }
Print("Done");
ExpertRemove();
}

void OnTick()
  { }

 
Lorentzos Roussos #:

has sdata loaded ?

try this funion also if it says cannot open fle check file permissions , if you are sent the file and not downloading it

The function was able to open it, but when I tested sData it is reading in non-latin characters in the log even though file is in english.

Files:
DataTest.png  11 kb
 
Jesse Phipps #:

The function was able to open it, but when I tested sData it is reading in non-latin characters in the log even though file is in english.

Use the function to load sdata then 

Maybe  the xml load opens in Unicode , uses short to string and CP_UTF8
 
Lorentzos Roussos #:

Use the function to load sdata then 

Maybe  the xml load opens in Unicode , uses short to string and CP_UTF8


Thank you, it was a unicode error. I've never run into this with MT4.