//+------------------------------------------------------------------+
//|                                           Disable EA on News.mq4 |
//|    Copyright © 2007-2016, Tradingsystemforex.com - Elite Section |
//|                              http://www.tradingsystemforex.com/  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007-2016, Tradingsystemforex.com - Elite Section"
/*
#define READURL_BUFFER_SIZE 100

#import "Wininet.dll"
   int InternetOpenW(string,int,string,string,int);
   int InternetConnectW(int,string,int,string,string,int,int,int); 
   int HttpOpenRequestW(int,string,string,int,string,int,string,int); 
   int InternetOpenUrlW(int,string,string,int,int,int);
   int InternetReadFile(int,uchar & arr[],int,int& OneInt[]);
   int InternetCloseHandle(int); 
#import
*/
#include <WinUser32.mqh>

#property show_inputs

input bool NewsLow         = false;
input bool NewsModerate    = false;
input bool NewsHigh        = true;

int SetMinutes            = 6;
int SetMinutesSpan        = 2;
int OneCancelOthers      = 0;
int SetMinBeforeNews    = 10; //Set orders x minutes before news
extern int ApplySecondsInterval = 5;
extern int DisableMinBeforeNews = 10;
extern int EnableMinAfterNews   = 10;
int MinimumImpact        = 3; // 1= low impact, 2= medium impact, 3= high impact
extern bool ForceALL            = false; //Force trading for "ALL" news
extern bool ForceAUD            = false; //Force trading for AUD news
extern bool ForceCAD            = false; //Force trading for CAD news
extern bool ForceCHF            = false; //Force trading for CHF news
extern bool ForceCNY            = false; //Force trading for CNY news
extern bool ForceEUR            = false; //Force trading for EUR news
extern bool ForceGBP            = false; //Force trading for GBP news
extern bool ForceJPY            = false; //Force trading for JPY news
extern bool ForceNZD            = false; //Force trading for NZD news
extern bool ForceUSD            = false; //Force trading for USD news

string NewsSymb      = "USD,EUR,GBP,CHF,CAD,AUD,NZD,JPY,CNY";

bool DrawLines       = false;
bool DisplayText     = false;
bool Next            = false;
bool Signal          = false;
int SignalAfterNews  = 5;
int SignalBeforeNews = 5;

input string Link          = "http://ec.forexprostools.com/?columns=exc_currency,exc_importance&importance=1,2,3&calType=week&timeZone=15&lang=1";

color highc=clrRed;
color mediumc=clrOrange;
color lowc=clrYellow;
int Style=2;
int Upd=86400;

int MinBefore=0;
int MinAfter=0;

bool high =false;
bool moderate=false;
bool low=false;

bool  NewsTime;
string comment="";
int minutesSincePrevEvent,minutesUntilNextEvent;

int nextnews0=0;

string comment1="",comment2="";

string news="";
string s1="",s2="";

int country1[150],country2[150];
string country[150],country0="",countryx="";

int title1[150],title2[150];
string title[150],title0="",titlex="";

int date1[150],date2[150];
string date[150],dateread[150],dateday[150],datemonth[150],dateyear[150],date0="",datex="";
datetime dategmt,datefinal[150];

int time1[150],time2[150],time3[150];
string time[150],timeread[150],timeap[150];
string hour[150],hour1[150],hour2[150];

int impact3[150],impactfinal[150],impact0,impactx;
string impactz[150];

int bufferlen,n,h,previ=150,nexti=150,zx=0,total;

datetime barw1;
bool res=false;

string status="";

string timecomment="";

int gmthour;
int gmtminute;
datetime timegmt; // Gmt time
datetime timecurrent; // Current time
int gmtoffset=0;

datetime newbar2;

int NomNews=0;
string NewsArr[4][1000];
int Now=0;
datetime LastUpd;
string str1;
int offset=0;

int j;
string innercommentnews2,innercommentnews;

int prevnews,nextnews;
int prev,next;

int calc=0;

//----------------------------------------------------------------- // News filter
/*
string geturl(string url){   
   int HttpOpen=InternetOpenW(" ",0," "," ",0); 
   int HttpConnect=InternetConnectW(HttpOpen,"",80,"","",3,0,1);
   int HttpRequest=InternetOpenUrlW(HttpOpen,url,NULL,0,0,0);

   int read[1];
   uchar Buffer[];
   ArrayResize(Buffer,READURL_BUFFER_SIZE+1);
   string page="";
   while(true){
      InternetReadFile(HttpRequest,Buffer,READURL_BUFFER_SIZE,read);
      string strThisRead=CharArrayToString(Buffer,0,read[0],CP_UTF8);
      if(read[0]>0)page=page+strThisRead;
      else break;
   }
   if(HttpRequest>0)InternetCloseHandle(HttpRequest);
   if(HttpConnect>0)InternetCloseHandle(HttpConnect);
   if(HttpOpen>0)InternetCloseHandle(HttpOpen);
   return page;
}

void news(){
if(barw1!=iTime(NULL,10080,0)){

      s1=StringSubstr(Symbol(),0,3);
      s2=StringSubstr(Symbol(),3,3);

      news=geturl("http://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;}

      innercommentnews2="";
      for(zx=0;zx<=500;zx++){
         if(country[zx]=="")break;
         if(country[zx]!="" && impactfinal[zx]>=MinimumImpact)
         innercommentnews2+="\n"+dateyear[zx]+"."+datemonth[zx]+"."+dateday[zx]+" "+hour[zx]+", "+country[zx]+", "+impactfinal[zx]+", "+title[zx];
      }
      if(innercommentnews2!="")barw1=iTime(NULL,10080,0);

   }
}
*/

void OnInit(){

   high=NewsHigh;
   moderate=NewsModerate;
   low=NewsLow;

   timegmt=TimeGMT();
   timecurrent=TimeCurrent();
   
   gmthour=(int)StringToDouble(StringSubstr(TimeToStr(timegmt),11,2));
   gmtminute=(int)StringToDouble(StringSubstr(TimeToStr(timegmt),14,2));
   gmtoffset=(int)TimeHour(timecurrent)-gmthour;
   if(gmtoffset<0)gmtoffset=24+gmtoffset;

   offset=(int)(TimeCurrent()-TimeGMT());
   if(StringLen(NewsSymb)>1)str1=NewsSymb;
   else str1=Symbol();

   high=NewsHigh;
   moderate=NewsModerate;
   low=NewsLow;
   
   MinBefore=SignalBeforeNews;
   MinAfter=SignalAfterNews;

   return(INIT_SUCCEEDED);
}

int start(){
   
  //initialise for other objects already existing
  //objectstotal = ObjectsTotal();
  
   while(IsStopped()==False){
   
   //if(newbar2!=iTime(NULL,1,0)){
/*
      timegmt=TimeGMT();
      gmthour=StringToDouble(StringSubstr(TimeToStr(timegmt),11,2));
      gmtminute=StringToDouble(StringSubstr(TimeToStr(timegmt),14,2));
   
      news();
   
      dategmt=TimeGMT();

      previ=150;
      nexti=150;
      for(n=0;n<=150;n++){
         if(dategmt<datefinal[n])break;
         if(impactfinal[n]>=MinimumImpact && (s1==country[n] || s2==country[n] || (ForceALL==true && "ALL"==country[n])
         || (ForceUSD==true && "USD"==country[n]) || (ForceCNY==true && "CNY"==country[n]) || (ForceGBP==true && "GBP"==country[n]) 
         || (ForceJPY==true && "JPY"==country[n]) || (ForceAUD==true && "AUD"==country[n]) || (ForceCAD==true && "CAD"==country[n]) 
         || (ForceCHF==true && "CHF"==country[n]) || (ForceEUR==true && "EUR"==country[n]) || (ForceNZD==true && "NZD"==country[n])))
         if(dategmt>datefinal[n] && datefinal[n]!=0)previ=n;
      }
      for(n=0;n<=150;n++){
         if(nexti!=150)break;
         if(impactfinal[n]>=MinimumImpact && (s1==country[n] || s2==country[n] || (ForceALL==true && "ALL"==country[n]) 
         || (ForceUSD==true && "USD"==country[n]) || (ForceCNY==true && "CNY"==country[n]) || (ForceGBP==true && "GBP"==country[n]) 
         || (ForceJPY==true && "JPY"==country[n]) || (ForceAUD==true && "AUD"==country[n]) || (ForceCAD==true && "CAD"==country[n]) 
         || (ForceCHF==true && "CHF"==country[n]) || (ForceEUR==true && "EUR"==country[n]) || (ForceNZD==true && "NZD"==country[n])))
         if(dategmt<datefinal[n])nexti=n;
      }

      title0=title[previ];
      impact0=impactfinal[previ];
      country0=country[previ];
      date0=TimeToStr(datefinal[previ]);
   
      titlex=title[nexti];
      impactx=impactfinal[nexti];
      countryx=country[nexti];
      datex=TimeToStr(datefinal[nexti]);

      prevnews=(dategmt-datefinal[previ])/60;//(datefinal[previ]-dategmt)/60;
      nextnews=(datefinal[nexti]-dategmt)/60;//(datefinal[nexti]-dategmt)/60;

      innercommentnews=
      "\n\n"+"Previous news "+date0+", "+country0+", "+impact0+", "+title0+", "+prevnews+" minutes ago."
      +"\n"+"Next news "+datex+", "+countryx+", "+impactx+", "+titlex+", in "+nextnews+" minutes.";
      
      status="Enable EA";
      if(prevnews<EnableMinAfterNews || (nextnews>=0 && nextnews<=DisableMinBeforeNews))status="Disable EA";
  
      Comment(
      "\nGMT Time : "+gmthour+":"+gmtminute+" "+timecomment+", GMT Offset "+gmtoffset,
      "\n"+innercommentnews2, // News filter
      innercommentnews,
      "\n\n Disable EA "+DisableMinBeforeNews+" minutes before the news",
      "\n Enable EA "+EnableMinAfterNews+" minutes after the news",
      "\n\n Status : "+status
      /*,
      "\n\n Previous news : "+IntegerToString(prevnews)+" minutes ago",
      "\n Previous news title : "+title0,
      "\n Previous news impact : "+impact0,
      "\n Previous news country : "+country0,
      "\n Previous news date : "+date0,
      "\n\n Next news : In "+IntegerToString(nextnews)+" minutes.",
      "\n Next news title : "+titlex,
      "\n Next news impact : "+impactx,
      "\n Next news country : "+countryx,
      "\n Next news date : "+datex*/
      //);
      
      //newbar2=iTime(NULL,1,0);
   //}
   
   
      s1=StringSubstr(Symbol(),0,3);
      s2=StringSubstr(Symbol(),3,3);
   
   if(calc==0){

   offset=(int)(TimeCurrent()-TimeGMT());
   double CheckNews=0;
   if(SignalAfterNews>0){
      if(TimeCurrent()-LastUpd>=Upd){
         Comment("News Loading...");
         Print("News Loading...");
         UpdateNews();
         LastUpd=TimeCurrent();
         Comment("");
      }
      WindowRedraw();
      
      //---------------event Processing------------------------------------
      
      int i;
      CheckNews=0;
      for(i=0;i<NomNews;i++){
         int power=0;
         if(high && StringFind(NewsArr[2][i],"High")>=0)power=1;
         if(moderate && StringFind(NewsArr[2][i],"Moderate")>=0)power=2;
         if(low && StringFind(NewsArr[2][i],"Low")>=0)power=3;
         if(power==0)continue;
         if(TimeCurrent()+MinBefore*60>TimeNewsFunck(i) && TimeCurrent()-MinAfter*60<TimeNewsFunck(i) && StringFind(str1,NewsArr[1][i])>=0){
            CheckNews=1;
            break;
         }
         else CheckNews=0;
      }
      if(CheckNews==1 && i!=Now && Signal){
         Alert("In ",(int)(TimeNewsFunck(i)-TimeCurrent())/60," minutes released news ",NewsArr[1][i],"_",NewsArr[3][i]);
         Now=i;
      }
   }
   /*if(CheckNews>0){
      Comment("News time");
   }else{
      Comment("No news");
   }*/
      calc=1;
   }
      prev=99999999;
      next=99999999;
      
      innercommentnews2="";
      for(j=0;j<NomNews;j++){
         if((ForceALL==false && (s1==NewsArr[1][j] || s2==NewsArr[1][j])) || ForceALL==true || (ForceAUD==true && NewsArr[1][j]=="AUD")
          || (ForceCAD==true && NewsArr[1][j]=="CAD") || (ForceCHF==true && NewsArr[1][j]=="CHF") || (ForceCNY==true && NewsArr[1][j]=="CNY")
           || (ForceEUR==true && NewsArr[1][j]=="EUR") || (ForceGBP==true && NewsArr[1][j]=="GBP") || (ForceJPY==true && NewsArr[1][j]=="JPY")
            || (ForceNZD==true && NewsArr[1][j]=="NZD") || (ForceUSD==true && NewsArr[1][j]=="USD")){
            innercommentnews2+="\n "+NewsArr[0][j]+", "+NewsArr[1][j]+", "+NewsArr[2][j]+", "+NewsArr[3][j];
            if(TimeCurrent()>TimeNewsFunck(j))prev=j;
         }
      }
      for(j=NomNews;j>=0;j--){
         if(TimeCurrent()<TimeNewsFunck(j))next=j;
      }
      
      /*
      extern int DisableMinBeforeNews = 10;
      extern int EnableMinAfterNews   = 10;
*/
      /*
      prevnews=(dategmt-datefinal[previ])/60;//(datefinal[previ]-dategmt)/60;
      nextnews=(datefinal[nexti]-dategmt)/60;
   */
   
      prevnews=(int)(TimeCurrent()-TimeNewsFunck(prev))/60;
      nextnews=(int)(TimeNewsFunck(next)-TimeCurrent())/60;
      
      innercommentnews=
      "\n"+"Previous news "+NewsArr[0][prev]+", "+NewsArr[1][prev]+", "+NewsArr[2][prev]+", "+NewsArr[3][prev]+", "+IntegerToString(prevnews)+" minutes ago."
      +"\n"+"Next news "+NewsArr[0][next]+", "+NewsArr[1][next]+", "+NewsArr[2][next]+", "+NewsArr[3][next]+", in "+IntegerToString(nextnews)+" minutes.";
      
      status="Enable EA";
      if(prevnews<EnableMinAfterNews || (nextnews>=0 && nextnews<=DisableMinBeforeNews))status="Disable EA";
      
      /*
      status="Enable EA";
      if(prevnews<EnableMinAfterNews || (nextnews>=0 && nextnews<=DisableMinBeforeNews))status="Disable EA";
      */
      /*
      Comment(
      "\nGMT Time : "+gmthour+":"+gmtminute+" "+timecomment+", GMT Offset "+gmtoffset,
      "\n"+innercommentnews2,
      innercommentnews,
      "\n\n Disable EA "+DisableMinBeforeNews+" minutes before the news",
      "\n Enable EA "+EnableMinAfterNews+" minutes after the news",
      "\n\n Status : "+status);*/
      
      Comment(
      "\nGMT Time : "+IntegerToString(gmthour)+":"+IntegerToString(gmtminute)+", GMT Offset "+IntegerToString(gmtoffset),
      "\n"+innercommentnews2,
      "\n"+innercommentnews,
      "\n\n Disable EA "+IntegerToString(DisableMinBeforeNews)+" minutes before the news",
      "\n Enable EA "+IntegerToString(EnableMinAfterNews)+" minutes after the news",
      "\n\n Status : "+status);
   
   
      if(status=="Enable EA")
         if(IsExpertEnabled()==false)DisableEA();
         
      if(status=="Disable EA")
         if(IsExpertEnabled()==true)DisableEA();
      
      Sleep(ApplySecondsInterval*1000);
      RefreshRates();

   }
}

void DisableEA(){
   keybd_event(17,0,0,0);
   keybd_event(69,0,0,0);
   keybd_event(69,0,2,0);
   keybd_event(17,0,2,0);
}

//+------------------------------------------------------------------+
//////////////////////////////////////////////////////////////////////////////////
// Download CBOE page source code in a text variable
// And returns the result
//////////////////////////////////////////////////////////////////////////////////
string ReadCBOE(){

   string cookie=NULL,headers;
   char post[],result[];
   string TXT="";
   int res2;
//--- to work with the server, you must add the URL "https://www.google.com/finance"  
//--- the list of allowed URL (Main menu-> Tools-> Settings tab "Advisors"): 
   string google_url="http://ec.forexprostools.com/?columns=exc_currency,exc_importance&importance=1,2,3&calType=week&timeZone=15&lang=1";
   ResetLastError();
//--- download html-pages
   int timeout=5000; //--- timeout less than 1,000 (1 sec.) is insufficient at a low speed of the Internet
   res2=WebRequest("GET",google_url,cookie,NULL,timeout,post,0,result,headers);
//--- error checking
   if(res2==-1){
      Print("WebRequest error, err.code  =",GetLastError());
      MessageBox("You must add the address ' "+google_url+"' in the list of allowed URL tab 'Advisors' "," Error ",MB_ICONINFORMATION);
      //--- You must add the address ' "+ google url"' in the list of allowed URL tab 'Advisors' "," Error "
   }
   else{
      //--- successful download
      //PrintFormat("File successfully downloaded, the file size in bytes  =%d.",ArraySize(result)); 
      //--- save the data in the file
      int filehandle=FileOpen("news-log.html",FILE_WRITE|FILE_BIN);

      if(filehandle!=INVALID_HANDLE){
         //---save the contents of the array result [] in file 
         FileWriteArray(filehandle,result,0,ArraySize(result));
         //--- close file 
         FileClose(filehandle);

         int filehandle2=FileOpen("news-log.html",FILE_READ|FILE_BIN);
         TXT=FileReadString(filehandle2,ArraySize(result));
         FileClose(filehandle2);
        }else{
         Print("Error in FileOpen. Error code =",GetLastError());
        }
     }
   return(TXT);
}

//------------------------------------------------------------------

datetime TimeNewsFunck(int nomf){
   string s=NewsArr[0][nomf];
   string time=StringConcatenate(StringSubstr(s,0,4),".",StringSubstr(s,5,2),".",StringSubstr(s,8,2)," ",StringSubstr(s,11,2),":",StringSubstr(s,14,4));
   return((datetime)(StringToTime(time)+offset));
}

//------------------------------------------------------------------

void UpdateNews(){
   string TEXT=ReadCBOE();
   int sh=StringFind(TEXT,"pageStartAt>")+12;
   int sh2=StringFind(TEXT,"</tbody>");
   TEXT=StringSubstr(TEXT,sh,sh2-sh);

   sh=0;
   while(!IsStopped()){
      sh=StringFind(TEXT,"event_timestamp",sh)+17;
      sh2=StringFind(TEXT,"onclick",sh)-2;
      if(sh<17 || sh2<0)break;
      NewsArr[0][NomNews]=StringSubstr(TEXT,sh,sh2-sh);

      sh=StringFind(TEXT,"flagCur",sh)+10;
      sh2=sh+3;
      if(sh<10 || sh2<3)break;
      NewsArr[1][NomNews]=StringSubstr(TEXT,sh,sh2-sh);
      if(StringFind(str1,NewsArr[1][NomNews])<0)continue;

      sh=StringFind(TEXT,"title",sh)+7;
      sh2= StringFind(TEXT,"Volatility",sh)-1;
      if(sh<7 || sh2<0)break;
      NewsArr[2][NomNews]=StringSubstr(TEXT,sh,sh2-sh);
      if(StringFind(NewsArr[2][NomNews],"High")>=0 && !high)continue;
      if(StringFind(NewsArr[2][NomNews],"Moderate")>=0 && !moderate)continue;
      if(StringFind(NewsArr[2][NomNews],"Low")>=0 && !low)continue;

      sh=StringFind(TEXT,"left event",sh)+12;
      int sh1=StringFind(TEXT,"Speaks",sh);
      sh2=StringFind(TEXT,"<",sh);
      if(sh<12 || sh2<0)break;
      if(sh1<0 || sh1>sh2)NewsArr[3][NomNews]=StringSubstr(TEXT,sh,sh2-sh);
      else NewsArr[3][NomNews]=StringSubstr(TEXT,sh,sh1-sh);

      NomNews++;
      if(NomNews==300)break;
   }
}
  
//------------------------------------------------------------------
