how to read forex news from forexfactory calendar with WebRequest

 

hi

in my ea, i would like to read the forex news  on 16/11/2015 from forexfactory calendar on 16/11/2015, i wrote this code:

void getNewsCalendar()
  {
   string cookie=NULL,headers;
   char post[],result[];
   int res;

   string calendar_url="http://www.forexfactory.com/calendar.php?day=nov16.2015";

   ResetLastError();

   int timeout=5000; 
   res=WebRequest("GET",calendar_url,cookie,NULL,timeout,post,0,result,headers);

   if(res==-1)
     {
      Print("Error in WebRequest. Error code  =",GetLastError());
      MessageBox("Add the address '"+calendar_url+"' in the list of allowed URLs on tab 'Expert Advisors'","Error",MB_ICONINFORMATION);
     }
   else
     {
     Print("Server response: ", CharArrayToString(result));  //<-- the output
     }
  }

 from this line of code:

Print("Server response: ", CharArrayToString(result));

 i get this output:

Server response: <!DOCTYPE html> <!--[if lt IE 7]> <html class="no-js ie ie6">
<![endif]--> <!--[if IE 7]> <html class="no-js ie ie7">
<![endif]--> <!--[if IE 8]> <html class="no-js ie ie8">
<![endif]--> <!--[if gt IE 8]> <html class="no-js ie ie9">
<![endif]--> <!--[if !IE]> <html class="no-js">
<![endif]--> <head> <base href="http://www.forexfactory.com/" /> <meta charset="iso-8859-1"> <meta name="viewport" content="width=device-width"> <meta name="keywords" content="

 it's incomplete, where is my error?

 

May be Print() is the false function? It could be that it has a limit of char to print.

Write the result into a file and check that!

 

hi gooly, thanks for your reply

i wolud read and parse each line of my "result" to find the title news

which code can i use to parse my string row by row? 

second question, can i get hte news in xml format so i can use a xml parse? 

 
andream1977:

which code can i use to parse my string row by row? 

Your own :)

First of all. I have experience in these things, because I already wrote such a thing as you can see here.

Second. The WebRequest function inside MQL4 does NOT work in Indikator-Mode. Only Scripts and Expert-Advisors are supported as you can read here under "Note".

You need to write either an HTML or XML Parser (or some other mechanism) to retreive the values you need and then further deal with the data.

An option (how I solved it by using MQL4) only is this approach. And I have choosen this approach because the "schema" or "style" of the Website code is most likely always the same. The things that differ are the values (news, numbers etc.) between the "schema". Sadly MQL4 doesn't support regex or similar stuff. Only basic string operations:

Parse string from left side.

Parse string from right side.

Example:

<div style="news">Microsoft Information blah</div>

Now you string Find this part:

<div style="news">

You get an position integer back

Then you string Find this part:

</div>

You get another position integer back

Now you use the first and second position integers to cut out (Substring) the text between the lines.

This sounds fairly complicated but it isn't the overall code is quite simple at the end.

Hope I was able to get you going.

BTW: You need to apply a timer e.g. get news all 3-5 minutes. If you run such an Indicator in all "Terminals" then be sure that you encounter *freezes* because of web operations and presentation etc. This is not necessarily code related but more of requesting and responsing to web server (which can be under heavy load). 

 

Hint:

1) I replace "</event>" by "|"

2) Now I split the whole file by '|' (only one char is allowed). // be aware of "|" and '|' !!

Now you have each event in one string

3) now split each event by '\n' and loop through the keywords..

 
andream1977:

hi

in my ea, i would like to read the forex news  on 16/11/2015 from forexfactory calendar on 16/11/2015, i wrote this code:

 from this line of code:

 i get this output:

 it's incomplete, where is my error?

i have a indicator which display news on your meta trader screen but getting error message is dll