News Update from Forex Factory

Apr 06, 2017 at 06:38
767 Visualizações
6 Replies
Membro Desde Aug 27, 2016   11 posts
Apr 06, 2017 at 06:38
Hi masters, I need some advice. Can anyone please explain what does below code mean? Please help....

void news(){
if(barw1!=iTime(NULL,15,0)){

      s1=StringSubstr(Symbol(),0,3);
      s2=StringSubstr(Symbol(),3,3);

      news=geturl('https://www.forexfactory.com/ffcal_week_this.xml'+'?'+TimeToString(iTime(NULL,1,0),0));
No Greed Is Always Green
Membro Desde Aug 20, 2009   266 posts
Apr 07, 2017 at 08:46
Eric,

Here you go..........

if(barw1!=iTime(NULL,15,0)){....................this is a filter so that it will follow this function once every 15 minutes.

s1=StringSubstr(Symbol(),0,3);
      s2=StringSubstr(Symbol(),3,3);.....................these 2 line separate the current Symbol(eg EURUSD) into 2 separate currencies, so s1 = EUR and s2 = USD.

news=geturl('https://www.forexfactory.com/ffcal_week_this.xml'+'?'+TimeToString(iTime(NULL,1,0),0));...........You would need to post the 'geturl' function in order to see what this does but if I were to guess, it looks to download the next news event(s) and stores it as a string into the 'news' variable. Presumably the rest of the function parses the string and matches results against s1 & s2 to see if there is any news event that affects this Symbol.
Wealth Creation Through Technology
Membro Desde Aug 27, 2016   11 posts
Apr 07, 2017 at 11:31
compuforexpamm posted:
Eric,

Here you go..........

if(barw1!=iTime(NULL,15,0)){....................this is a filter so that it will follow this function once every 15 minutes.

s1=StringSubstr(Symbol(),0,3);
      s2=StringSubstr(Symbol(),3,3);.....................these 2 line separate the current Symbol(eg EURUSD) into 2 separate currencies, so s1 = EUR and s2 = USD.

news=geturl('https://www.forexfactory.com/ffcal_week_this.xml'+'?'+TimeToString(iTime(NULL,1,0),0));...........You would need to post the 'geturl' function in order to see what this does but if I were to guess, it looks to download the next news event(s) and stores it as a string into the 'news' variable. Presumably the rest of the function parses the string and matches results against s1 & s2 to see if there is any news event that affects this Symbol.

Hi kennyhubbard,

Thank you for your reply, highly appreciated. You have made it very clear, now I understand. This really help.
No Greed Is Always Green
Membro Desde Aug 27, 2016   11 posts
Apr 07, 2017 at 11:31
compuforexpamm posted:
Eric,

Here you go..........

if(barw1!=iTime(NULL,15,0)){....................this is a filter so that it will follow this function once every 15 minutes.

s1=StringSubstr(Symbol(),0,3);
      s2=StringSubstr(Symbol(),3,3);.....................these 2 line separate the current Symbol(eg EURUSD) into 2 separate currencies, so s1 = EUR and s2 = USD.

news=geturl('https://www.forexfactory.com/ffcal_week_this.xml'+'?'+TimeToString(iTime(NULL,1,0),0));...........You would need to post the 'geturl' function in order to see what this does but if I were to guess, it looks to download the next news event(s) and stores it as a string into the 'news' variable. Presumably the rest of the function parses the string and matches results against s1 & s2 to see if there is any news event that affects this Symbol.

kennyhubbard,

Below is the full code, with your helpful explanation, I changed the filter to function once every 4 hours to extract news updates from forex factory. FF has updated it's website to block IP address for high request coming from a single source alone. I had to change this code line in order for the EA's news filter function to work normally again. Appreciate if you could take a moment to check below codes are correct. Attached image how it looks like on the news filter function. Looking forward to your valuable reply.

void news(){
if(barw1!=iTime(NULL,240,0)){

      s1=StringSubstr(Symbol(),0,3);
      s2=StringSubstr(Symbol(),3,3);

      news=geturl('https://www.forexfactory.com/ffcal_week_this.xml'+'?'+TimeToString(iTime(NULL,1,0),0));

      bufferlen=StringBufferLen(news);

      h=0;for(n=0;n<=bufferlen;n++){if(StringFind(news,'<country>',n)!=-1){country1[h]=StringFind(news,'<country>',n);h++;n=StringFind(news,'<country>',n)+1;}}
      h=0;for(n=0;n<=bufferlen;n++){if(StringFind(news,'</country>',n)!=-1){country2[h]=StringFind(news,'</country>',n);h++;n=StringFind(news,'</country>',n)+1;}}
      for(n=0;n<=150;n++){country[n]=StringSubstr(news,country1[n]+9,country2[n]-(country1[n]+9));}

      h=0;for(n=0;n<=bufferlen;n++){if(StringFind(news,'<title>',n)!=-1){title1[h]=StringFind(news,'<title>',n);h++;n=StringFind(news,'<title>',n)+1;}}
      h=0;for(n=0;n<=bufferlen;n++){if(StringFind(news,'</title>',n)!=-1){title2[h]=StringFind(news,'</title>',n);h++;n=StringFind(news,'</title>',n)+1;}}
      for(n=0;n<=150;n++){title[n]=StringSubstr(news,title1[n]+7,title2[n]-(title1[n]+7));}

      h=0;for(n=0;n<=bufferlen;n++){if(StringFind(news,'<date>',n)!=-1){date1[h]=StringFind(news,'<date>',n);h++;n=StringFind(news,'<date>',n)+1;}}
      h=0;for(n=0;n<=bufferlen;n++){if(StringFind(news,'</date>',n)!=-1){date2[h]=StringFind(news,'</date>',n);h++;n=StringFind(news,'</date>',n)+1;}}
      for(n=0;n<=150;n++){date[n]=StringSubstr(news,date1[n]+15,date2[n]-(date1[n]+18));}
      for(n=0;n<=150;n++){dateread[n]=StringSubstr(date[n],0,10);}
      for(n=0;n<=150;n++){dateday[n]=StringSubstr(dateread[n],3,2);if(StringSubstr(dateday[n],0,1)=='0')dateday[n]=StringSubstr(dateday[n],1,1);}
      for(n=0;n<=150;n++){datemonth[n]=StringSubstr(dateread[n],0,2);if(StringSubstr(datemonth[n],0,1)=='0')datemonth[n]=StringSubstr(datemonth[n],1,1);}
      for(n=0;n<=150;n++){dateyear[n]=StringSubstr(dateread[n],6,4);}

      h=0;for(n=0;n<=bufferlen;n++){if(StringFind(news,'<time>',n)!=-1){time1[h]=StringFind(news,'<time>',n);h++;n=StringFind(news,'<time>',n)+1;}}
      h=0;for(n=0;n<=bufferlen;n++){if(StringFind(news,'</time>',n)!=-1){time2[h]=StringFind(news,'</time>',n);h++;n=StringFind(news,'</time>',n)+1;}}
      for(n=0;n<=150;n++){time[n]=StringSubstr(news,time1[n]+15,time2[n]-(time1[n]+18));}
      for(n=0;n<=150;n++)time3[n]=StringFind(time[n],':',0);
      for(n=0;n<=150;n++){if(time3[n]==1)timeap[n]=StringSubstr(time[n],4,2);else timeap[n]=StringSubstr(time[n],5,2);}
      for(n=0;n<=150;n++){if(time3[n]==1)timeread[n]=StringSubstr(time[n],0,4);else timeread[n]=StringSubstr(time[n],0,5);}
      for(n=0;n<=150;n++){
         if(time3[n]==1){
            if(timeap[n]=='am'){
               hour1[n]=StringSubstr(timeread[n],0,1);
               if(hour1[n]=='1')hour1[n]='01';
               if(hour1[n]=='2')hour1[n]='02';
               if(hour1[n]=='3')hour1[n]='03';
               if(hour1[n]=='4')hour1[n]='04';
               if(hour1[n]=='5')hour1[n]='05';
               if(hour1[n]=='6')hour1[n]='06';
               if(hour1[n]=='7')hour1[n]='07';
               if(hour1[n]=='8')hour1[n]='08';
               if(hour1[n]=='9')hour1[n]='09';
               hour2[n]=StringSubstr(timeread[n],2,2);
               hour[n]=hour1[n]+':'+hour2[n];
            }
            if(timeap[n]=='pm'){
               hour1[n]=StringSubstr(timeread[n],0,1);
               if(hour1[n]=='1')hour1[n]='13';
               if(hour1[n]=='2')hour1[n]='14';
               if(hour1[n]=='3')hour1[n]='15';
               if(hour1[n]=='4')hour1[n]='16';
               if(hour1[n]=='5')hour1[n]='17';
               if(hour1[n]=='6')hour1[n]='18';
               if(hour1[n]=='7')hour1[n]='19';
               if(hour1[n]=='8')hour1[n]='20';
               if(hour1[n]=='9')hour1[n]='21';
               hour2[n]=StringSubstr(timeread[n],2,2);
               hour[n]=hour1[n]+':'+hour2[n];
            }
         }
         else {
            if(timeap[n]=='am'){
               hour1[n]=StringSubstr(timeread[n],0,2);
               if(hour1[n]=='12')hour1[n]='00';
               hour2[n]=StringSubstr(timeread[n],3,2);
               hour[n]=hour1[n]+':'+hour2[n];
            }
            if(timeap[n]=='pm'){
               hour1[n]=StringSubstr(timeread[n],0,2);
               if(hour1[n]=='10')hour1[n]='22';
               if(hour1[n]=='11')hour1[n]='23';
               hour2[n]=StringSubstr(timeread[n],3,2);
               hour[n]=hour1[n]+':'+hour2[n];
            }
         }
      }

      for(n=0;n<=150;n++)datefinal[n]=StrToTime(dateyear[n]+'.'+datemonth[n]+'.'+dateday[n]+' '+hour[n]);

      for(n=0;n<=150;n++){impactz[n]=StringSubstr(news,time2[n]+27,6);}
      for(n=0;n<=150;n++){if(impactz[n]=='Low]]>')impactfinal[n]=1;if(impactz[n]=='Medium')impactfinal[n]=2;if(impactz[n]=='High]]')impactfinal[n]=3;}

     
   }
}






Anexos:

No Greed Is Always Green
Membro Desde Aug 20, 2009   266 posts
Apr 09, 2017 at 06:55
Hi Eric,

I haven't really gone through the parsing code as it is too complex to just read. I would need to run it to see aif tbere are any problems.

That said, the change to 240 in the first line looks about right.

Also, there should be a line lime this in your function :-

barw1 = iTime(NULL,240,0);

What it is doing is checking all the time if barw1 is tbe same time as the opening of tbe current H4 bar. If it isn't that means that a nee bar has started. In order to stop your function from running all the time, you need to set barw1 equal to the current bar time and that way, on the next tick, it will find that it doesn't need to run the function.
Wealth Creation Through Technology
Membro Desde Aug 20, 2009   266 posts
Apr 09, 2017 at 06:55
Sorry typing on my phone so lots of mistakes🙄
Wealth Creation Through Technology
Membro Desde Aug 27, 2016   11 posts
Apr 09, 2017 at 11:42
compuforexpamm posted:
Also, there should be a line like this in your function :-

barw1 = iTime(NULL,240,0);

What it is doing is checking all the time if barw1 is tbe same time as the opening of the current H4 bar. If it isn't that means that a new bar has started. In order to stop your function from running all the time, you need to set barw1 equal to the current bar time and that way, on the next tick, it will find that it doesn't need to run the function.

Hi compuforexpamm,

Thank for your reply. Do you mean I'm missing this code - barw1 = iTime(NULL,240,0); ??? Where should I put this code line?

Can you please advice & show me where should the line be based on below originals?

if(barw1!=iTime(NULL,240,0)){

      s1=StringSubstr(Symbol(),0,3);
      s2=StringSubstr(Symbol(),3,3);

      news=geturl('https://www.forexfactory.com/ffcal_week_this.xml'+'?'+TimeToString(iTime(NULL,1,0),0));

I'm so sorry, I don't know programming and I don't know how to correct it according to your advice. Can you please help me to correct the coding please. My Apologies for troubling you so much.

Thanks & regards,
Eric O.

No Greed Is Always Green
Autenticar / Sair to comment
You must be connected to Myfxbook in order to leave a comment
*Uso comercial e spam não serão tolerados, podendo resultar no encerramento da conta.
Dica: Postar uma imagem/URL do YouTube irá incorporá-la automaticamente no seu post!
Dica: Insira o sinal @ para preencher automaticamente um nome de utilizador que participe nesta discussão.