Ind_-_NewsInfo_v5

Author: Copyright � 2008-2012, EXPFOREX
Price Data Components
Series array that contains open time of each bar
Miscellaneous
Uses files from the file systemIt issuies visual alerts to the screenIt writes information to fileIt reads information from a file
0 Views
0 Downloads
0 Favorites
Ind_-_NewsInfo_v5
//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008-2012, EXPFOREX"
#property link      "http://www.expforex.com"
/*
Ðåàëüíûé àâòîð:
 "Ñåðãåé (urdala) Ðàøåâñêèé"
     "urdala@mail.ru"
     
     Ìîäèôèêàöèÿ è óëó÷øåíèå http://www.expforex.com
*/
#property indicator_chart_window
#property indicator_buffers 1
extern string in43="Ïîêàçûâàòü èñòîðèþ íîâîñòåé 1-ìåñÿö 2-ãîä";
extern int HistoryNewsShow=0;
extern string a1="Ìèíóò äî íîâîñòè";
extern int MinAlertPerNews=30; //Ñðàáàòûâàíèå ìèíóò äî íîâîñòè     
extern string a2="Ìèíóò ïîñëå íîâîñòè";
extern int MinAlertAfterNews=30; //Ñðàáàòûâàíèå ìèíóò ïîñëå íîâîñòè
extern string a3="×àñîâîé ïîÿñ";
extern int GMT=-1; // ÷àñîâîé ïîÿñ. 0-GMT 
extern string a4="Ïîêàçûâàòü âàæíûå íîâîñòè";
extern bool HighNews=true;//Óñòàíîâêà âàæíîñòè íîâîñòåé
extern string a5="Ïîêàçûâàòü ñðåäíèå íîâîñòè";
extern bool MediumNews=true;//Óñòàíîâêà âàæíîñòè íîâîñòåé
extern string a6="Ïîêàçûâàòü ëåãêèå íîâîñòè";
extern bool LowNews=true;//Óñòàíîâêà âàæíîñòè íîâîñòåé 
extern string a7="Ðèñîâàòü ëèíèè íîâîñòåé";
extern bool LineCreate=true;// Ðèñîâàòü ëèíèè?
extern string a34="Ðèñîâàòü òåêñò íîâîñòåé";
extern bool TextCreate=true;// Ðèñîâàòü ëèíèè?

bool LastWeekCreate=false;// Ðèñîâàòü òîëüêî ëèíèè áóäóùèõ íîâîñòåé?  
extern string a9="Ïîäàâàòü ñèãíàëû";
extern bool Alerts=false;// Ñèãíàëèòü î ïðåäñòîÿùåé íîâîñòè?
extern string a10="Öâåò âàæíûõ íîâîñòåé";
extern color high=Red;// öâåò âàæíûõ íîâîñòåé
extern string a11="Öâåò ñðåäíèõ íîâîñòåé";
extern color medium=Yellow;// öâåò îáû÷íûõ íîâîñòåé
extern string a12="Öâåò ëåãêèõ íîâîñòåé";
extern color low=Lime;// öâåò íåçíà÷èòåëüíûõ íîâîñòåé 
extern string a13="Ñòèëü ëèíèé";
extern int Style=0;//Ñòèëü ëèíèè  
//--------------------------------------------------------------------
#import "wininet.dll"
int InternetAttemptConnect(int x);
int InternetOpenA(string sAgent,int lAccessType,
                  string sProxyName="",string sProxyBypass="",
                  int lFlags=0);
int InternetOpenUrlA(int hInternetSession,string sUrl,
                     string sHeaders="",int lHeadersLength=0,
                     int lFlags=0,int lContext=0);
int InternetReadFile(int hFile,int &sBuffer[],int lNumBytesToRead,
                     int &lNumberOfBytesRead[]);
int InternetCloseHandle(int hInet);
#import
//---------------------------------------------------------------------
double Torg[1];
int TimeNews[300];
string Valuta[300];
string News[300];
string Vazn[300];
string Prognoz[300];
string Prev[300];
string Actual[300];
int Now=0;
int nom;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Stamp2()
  {

   ObjectCreate("Original",OBJ_LABEL,0,0,0);
   ObjectSetText("Original"," ---Ðàçðàáîòêà/Ìîäèôèêàöèÿ www.expforex.com---",10,"Arial Bold",Red);
   ObjectSet("Original",OBJPROP_CORNER,1);
   ObjectSet("Original",OBJPROP_XDISTANCE,250);
   ObjectSet("Original",OBJPROP_YDISTANCE,10);

  }
//---------------------------------------------------------------------
int timecur;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   Stamp2();

   IndicatorBuffers(1);
   SetIndexBuffer(0,Torg);
//----------Íàõîäèì ïîñëåäíåå âîñêðåñåíüå(ïîñëåäíèé çàãðóæåíûé íà ñàéò êàëåíäàðü)
   int DayFile=TimeDay(TimeCurrent()-TimeDayOfWeek(TimeCurrent())*86400);
   if(DayFile<10)string DF="0"+DayFile;
   else DF=DayFile;
   int MonthFile=TimeMonth(TimeCurrent()-TimeDayOfWeek(TimeCurrent())*86400);
   if(MonthFile<10)string MF="0"+MonthFile;
   else MF=MonthFile;
   int YearFile=TimeYear(TimeCurrent()-TimeDayOfWeek(TimeCurrent())*86400);
   string DateFile=MF+"-"+DF+"-"+YearFile;
   string FileName=DateFile+".csv";
   int handle;
   handle=FileOpen(FileName,FILE_CSV|FILE_READ,";");

   if(handle<0)
     {
      //-----Ñêà÷èâàåì êàëåíäàðü ---------------------------------------------------------------------   
      string url="http://www.dailyfx.com/files/Calendar-"+DateFile+".csv";
      //-------Ôóíêöèÿ ÷èòàåò èñõîäíûé êîä ñòðàíèöû ñàéòà â ñòðîêó------------------------------------
      if(!IsDllsAllowed())
        {
         Alert("Íåîáõîäèìî â íàñòðîéêàõ ðàçðåøèòü èñïîëüçîâàíèå DLL");
         return(0);
        }
      int rv = InternetAttemptConnect(0);
      if(rv != 0)
        {
         Alert("Îøèáêà ïðè âûçîâå InternetAttemptConnect()");
         return(0);
        }
      int hInternetSession=InternetOpenA("Microsoft Internet Explorer",
                                         0,"","",0);
      if(hInternetSession<=0)
        {
         Alert("Îøèáêà ïðè âûçîâå InternetOpenA()");
         return(0);
        }
      int hURL=InternetOpenUrlA(hInternetSession,
                                url,"",0,0,0);
      if(hURL<=0)
        {
         Alert("Îøèáêà ïðè âûçîâå InternetOpenUrlA()");
         InternetCloseHandle(hInternetSession);
         return(0);
        }
      //------------------------------------------------------------------------      
      handle=FileOpen(FileName,FILE_CSV|FILE_WRITE,";");
      int dwBytesRead[1],N1,N2,N3,N4;
      string text="";
      string Str[10];
      for(int y=0;y<9;y++)Str[y]="";
      nom=0;
      int x=0;
      while(!IsStopped())
        {
         int cBuffer[256];
         bool bResult=InternetReadFile(hURL,cBuffer,1024,dwBytesRead);
         if(dwBytesRead[0]==0) break;
         for(int i=0; i<256; i++)
           {

            N1=cBuffer[i] & 0x000000FF;
            N2=cBuffer[i] >> 8 & 0x000000FF;
            N3=cBuffer[i] >> 16 & 0x000000FF;
            N4=cBuffer[i] >> 24 & 0x000000FF;
            if(N1!=44 && N1!=10)Str[x]=Str[x]+CharToStr(N1);
            else x++;
            if(N1==10){nom++;x=0;FileWrite(handle,Str[0],Str[1],Str[2],Str[3],Str[4],Str[5],Str[6],Str[7],Str[8]);for(y=0;y<9;y++)Str[y]="";}
            if((i*4)==dwBytesRead[0])break;
            if(N2!=44 && N2!=10)Str[x]=Str[x]+CharToStr(N2);
            else x++;
            if(N2==10){nom++;x=0;FileWrite(handle,Str[0],Str[1],Str[2],Str[3],Str[4],Str[5],Str[6],Str[7],Str[8]);for(y=0;y<9;y++)Str[y]="";}
            if((i*4)+1==dwBytesRead[0])break;
            if(N3!=44 && N3!=10)Str[x]=Str[x]+CharToStr(N3);
            else x++;
            if(N3==10){nom++;x=0;FileWrite(handle,Str[0],Str[1],Str[2],Str[3],Str[4],Str[5],Str[6],Str[7],Str[8]);for(y=0;y<9;y++)Str[y]="";}
            if((i*4)+2==dwBytesRead[0])break;
            if(N4!=44 && N4!=10)Str[x]=Str[x]+CharToStr(N4);
            else x++;
            if(N4==10){nom++;x=0;FileWrite(handle,Str[0],Str[1],Str[2],Str[3],Str[4],Str[5],Str[6],Str[7],Str[8]);for(y=0;y<9;y++)Str[y]="";}
            if((i*4)+3==dwBytesRead[0])break;
           }
        }
      InternetCloseHandle(hInternetSession);
      FileSeek(handle,0,SEEK_SET);
      FileWrite(handle,nom);
     }
   FileClose(handle);
//-----------Çàíîñèì äàííûå èç ôàéëà â ìàññèâû.---------------------------------
   handle=FileOpen(FileName,FILE_CSV|FILE_READ,";");
   nom=StrToInteger(FileReadString(handle));
   string Hand;
   for(i=1;i<=8;i++)Hand=FileReadString(handle);
   string data,time,month,poyas,valuta;

   for(i=1;i<=nom;i++)
     {
      data=FileReadString(handle);
      time=FileReadString(handle);
      month=StringSubstr(data,4,3);
      if(month=="Jan") month="01";
      if(month=="Feb") month="02";
      if(month=="Mar") month="03";
      if(month=="Apr") month="04";
      if(month=="May") month="05";
      if(month=="Jun") month="06";
      if(month=="Jul") month="07";
      if(month=="Aug") month="08";
      if(month=="Sep") month="09";
      if(month=="Oct") month="10";
      if(month=="Nov") month="11";
      if(month=="Dec") month="12";
     if(time!="") TimeNews[i]=StrToTime(YearFile+"."+month+"."+StringSubstr(data,8,2)+" "+time)+GMT*3600;
     if(time=="") TimeNews[i]=0;
      
      text=FileReadString(handle);

      valuta=FileReadString(handle);
      if(valuta=="eur" ||valuta=="EUR")Valuta[i]="EUR";
      if(valuta=="usd" ||valuta=="USD")Valuta[i]="USD";
      if(valuta=="jpy" ||valuta=="JPY")Valuta[i]="JPY";
      if(valuta=="gbp" ||valuta=="GBP")Valuta[i]="GBP";
      if(valuta=="chf" ||valuta=="CHF")Valuta[i]="CHF";
      if(valuta=="cad" ||valuta=="CAD")Valuta[i]="CAD";
      if(valuta=="aud" ||valuta=="AUD")Valuta[i]="AUD";
      if(valuta=="nzd" ||valuta=="NZD")Valuta[i]="NZD";

      News[i]=FileReadString(handle);

      Vazn[i]=FileReadString(handle);
      if(Vazn[i]!="High" && Vazn[i]!="HIGH" && Vazn[i]!="Medium" && Vazn[i]!="MEDIUM" && Vazn[i]!="Low" && Vazn[i]!="LOW")Vazn[i]=FileReadString(handle);
      if(Vazn[i]!="High" && Vazn[i]!="HIGH" && Vazn[i]!="Medium" && Vazn[i]!="MEDIUM" && Vazn[i]!="Low" && Vazn[i]!="LOW")Vazn[i]=FileReadString(handle);
      if(Vazn[i]!="High" && Vazn[i]!="HIGH" && Vazn[i]!="Medium" && Vazn[i]!="MEDIUM" && Vazn[i]!="Low" && Vazn[i]!="LOW")Vazn[i]=FileReadString(handle);



      Actual[i]=FileReadString(handle);
      Prognoz[i]=FileReadString(handle);
      Prev[i]=FileReadString(handle);

      while(!IsStopped())
        {
         text=FileReadString(handle);
         if(FileIsLineEnding(handle))break;
        }
     }

//------------Âûõîä èç ôóíêöèè--------------------------------------------------
   FileClose(handle);
   return(0);
  }
//------------------------------------------------------------------------------
int deinit()
  {
   Stamp2();
   ObjectsDeleteAll(0,OBJ_ARROW);
   ObjectsDeleteAll(0,OBJ_VLINE);
   ObjectsDeleteAll(0,OBJ_LABEL);

   return(0);
  }

//-------------------------------------------------------------------------------







int start()
  {


   int i=1;           color Col;

//---Ðèñóåì ëèíèè íîâîñòåé íà ãðàôèêå--------------------------------------------
   if(LineCreate)
     {
      int na=0;
      int bartime[];
      ArrayResize(bartime,nom);
      for(int o=nom;o>=1;o--)
        {
         if(News[o]=="")continue;
         if(StringSubstr(Symbol(),0,3)!=Valuta[o] && StringSubstr(Symbol(),3,3)!=Valuta[o])continue;
         if((Vazn[o]=="High" || Vazn[o]=="HIGH") && HighNews==false)continue;
         if((Vazn[o]=="Medium" || Vazn[o]=="MEDIUM") && MediumNews==false)continue;
         if((Vazn[o]=="Low" || Vazn[o]=="LOW") && LowNews==false)continue;

         bartime[o]=TimeNews[o];
        }
      int predTime=-1;
      for(i=1;i<nom;i++)
        {

         if(News[i]=="")continue;
         if(TimeNews[i]==0)continue;
         
         // if (ObjectFind(News[i])==0)continue;
         if(StringSubstr(Symbol(),0,3)!=Valuta[i] && StringSubstr(Symbol(),3,3)!=Valuta[i])continue;
         if((Vazn[i]=="High" || Vazn[i]=="HIGH") && HighNews==false)continue;
         if((Vazn[i]=="Medium" || Vazn[i]=="MEDIUM") && MediumNews==false)continue;
         if((Vazn[i]=="Low" || Vazn[i]=="LOW") && LowNews==false)continue;
         if(Vazn[i]=="High"|| Vazn[i]=="HIGH")Col=high;
         if(Vazn[i]=="Medium"|| Vazn[i]=="MEDIUM")Col=medium;
         if(Vazn[i]=="Low"|| Vazn[i]=="LOW")Col=low;

         ObjectCreate("line"+News[i],OBJ_VLINE,0,TimeNews[i],0);
         ObjectSet("line"+News[i],OBJPROP_STYLE,1);
         ObjectSet("line"+News[i],OBJPROP_COLOR,Col);

         if(bartime[ArrayBsearch(bartime,TimeNews[i])]!=bartime[i]){na++;bartime[i]=-1; }else na=0;
         if(TimeDayOfWeek(TimeNews[i])!=predTime){na=0;predTime=TimeDayOfWeek(TimeNews[i]);}
         double raz=WindowPriceMax(0)-WindowPriceMin(0);
         ObjectCreate(News[i],OBJ_ARROW,0,0,0);
         ObjectSet(News[i],OBJPROP_TIME1,TimeNews[i]);
         ObjectSet(News[i],OBJPROP_PRICE1,High[iBarShift(Symbol(),0,TimeNews[i])]+na*raz/42);



         if(Vazn[i]=="Low"|| Vazn[i]=="LOW")ObjectSet(News[i],OBJPROP_ARROWCODE,140);
         if(Vazn[i]=="Medium"|| Vazn[i]=="MEDIUM")ObjectSet(News[i],OBJPROP_ARROWCODE,144);
         if(Vazn[i]=="High"|| Vazn[i]=="HIGH")ObjectSet(News[i],OBJPROP_ARROWCODE,149);
         ObjectSet(News[i],OBJPROP_COLOR,Col);
         ObjectSet(News[i],OBJPROP_STYLE,Style);
         ObjectSet(News[i],OBJPROP_RAY,false);

        }
     }
//---------------Îáðàáîòêà ñîáûòèé------------------------------------
   for(i=1;i<nom;i++)
     {
      if((Vazn[i]=="High" || Vazn[i]=="HIGH") && HighNews==false)continue;
      if((Vazn[i]=="Medium" || Vazn[i]=="MEDIUM") && MediumNews==false)continue;
      if((Vazn[i]=="Low" || Vazn[i]=="LOW") && LowNews==false)continue;
      if(TimeCurrent()+MinAlertPerNews*60>TimeNews[i] && TimeCurrent()-MinAlertAfterNews*60<TimeNews[i] && (StringSubstr(Symbol(),0,3)==Valuta[i] || StringSubstr(Symbol(),3,3)==Valuta[i]))
        {
         Torg[0]=1;
         break;
        }
      else Torg[0]=0;

     }
   if(Torg[0]==1 && i!=Now && Alerts) {Alert("×åðåç ",(TimeNews[i]-TimeCurrent())/60," ìèíóò áóäåò íîâîñòü ",News[i]);Now=i;}

   int t=0;
//------------------Êîìåíòàðèé-------------------------- 
   if(TextCreate)
     {
      int lastperty;
      for(i=1;i<nom;i++)
        {
         if(TimeNews[i]>TimeCurrent())break;
         lastperty=i;
        }

      for(i=lastperty-10;i<=lastperty+20;i++)
        {
         if(StringSubstr(Symbol(),0,3)!=Valuta[i] && StringSubstr(Symbol(),3,3)!=Valuta[i])continue;
         if((Vazn[i]=="High" || Vazn[i]=="HIGH") && HighNews==false)continue;
         if((Vazn[i]=="Medium" || Vazn[i]=="MEDIUM") && MediumNews==false)continue;
         if((Vazn[i]=="Low" || Vazn[i]=="LOW") && LowNews==false)continue;

         if(Vazn[i]=="High")Col=high;
         if(Vazn[i]=="Medium")Col=medium;
         if(Vazn[i]=="Low")Col=low;

         bool linet;
         if(TimeCurrent()>TimeNews[i]){SetLabel("NewInfos"+t,t,TimeToStr(TimeNews[i],TIME_DATE|TIME_MINUTES)," "+News[i]," Ïðåä:"+Prev[i]+" Ïðîãíîç:"+Prognoz[i]+" Ôàêò:"+Actual[i]," Ïðîøëî:"+((TimeCurrent()-TimeNews[i])/60)+" ìèíóò",Col,10);linet=true;}
         if(TimeCurrent()<=TimeNews[i] && linet){SetLabel("NAMERAZD",t,"======================================================================================================================================");t++;linet=false;}
         if(TimeCurrent()<=TimeNews[i])SetLabel("NewInfos"+t,t,TimeToStr(TimeNews[i],TIME_DATE|TIME_MINUTES)," "+News[i], " Ïðåä:"+Prev[i]+" Ïðîãíîç:"+Prognoz[i]+" Ôàêò:"+Actual[i], " Îñòàëîñü:"+((TimeNews[i]-TimeCurrent())/60)+" ìèíóò",Col,10);


         t++;
        }
        for(int h=t;h<100;h++)
        {if(ObjectFind("NewInfos"+h)!=-1)ObjectDelete("NewInfos"+h);}

     }
        if(HistoryNewsShow!=0)initHistory(HistoryNewsShow);

//-------------------------------------------------------------------------------
   return(0);
  }
//+------------------------------------------------------------------+







void SetLabel(string nm,int yt,string time="-",string tx="-",string par="-",string left="-",color cl=Blue,int xd=20,int cr=2,int fs=9) 
  {
   int yc;
   yc=yt*(fs+3);

   if(ObjectFind(nm+"time")<0) ObjectCreate(nm+"time",OBJ_LABEL,0,0,0);
   ObjectSetText(nm+"time",time,fs);
   ObjectSet(nm+"time",OBJPROP_COLOR,cl);
   ObjectSet(nm+"time",OBJPROP_XDISTANCE,xd);
   ObjectSet(nm+"time",OBJPROP_YDISTANCE,yc);
   ObjectSet(nm+"time",OBJPROP_CORNER,cr);
   ObjectSet(nm+"time",OBJPROP_FONTSIZE,fs);

   if(ObjectFind(nm)<0) ObjectCreate(nm,OBJ_LABEL,0,0,0);
   ObjectSetText(nm,tx,fs);
   ObjectSet(nm,OBJPROP_COLOR,cl);
   ObjectSet(nm,OBJPROP_XDISTANCE,xd+StringLen(time)*7);
   ObjectSet(nm,OBJPROP_YDISTANCE,yc);
   ObjectSet(nm,OBJPROP_CORNER,cr);
   ObjectSet(nm,OBJPROP_FONTSIZE,fs);

   if(ObjectFind(nm+"prog")<0) ObjectCreate(nm+"prog",OBJ_LABEL,0,0,0);
   ObjectSetText(nm+"prog",par,fs);
   ObjectSet(nm+"prog",OBJPROP_COLOR,cl);
   ObjectSet(nm+"prog",OBJPROP_XDISTANCE,xd+550);
   ObjectSet(nm+"prog",OBJPROP_YDISTANCE,yc);
   ObjectSet(nm+"prog",OBJPROP_CORNER,cr);
   ObjectSet(nm+"prog",OBJPROP_FONTSIZE,fs);

   if(ObjectFind(nm+"left")<0) ObjectCreate(nm+"left",OBJ_LABEL,0,0,0);
   ObjectSetText(nm+"left",left,fs);
   ObjectSet(nm+"left",OBJPROP_COLOR,cl);
   ObjectSet(nm+"left",OBJPROP_XDISTANCE,xd+750);
   ObjectSet(nm+"left",OBJPROP_YDISTANCE,yc);
   ObjectSet(nm+"left",OBJPROP_CORNER,cr);
   ObjectSet(nm+"left",OBJPROP_FONTSIZE,fs);

  }
//===========================================================================================================================================
//===========================================================================================================================================
//===========================================================================================================================================
//===========================================================================================================================================
//===========================================================================================================================================
//===========================================================================================================================================

double raznica;
int initHistory(int type)
  {
   int timecurentnew;
if(raznica==WindowPriceMax(0)-WindowPriceMin(0))return(-1);
raznica=WindowPriceMax(0)-WindowPriceMin(0);
int do;
if(type==1)do=TimeDay(TimeCurrent());
if(type==2)do=TimeDayOfYear(TimeCurrent());

   for(int ye=1;ye<do;ye++)

     {
      timecurentnew=TimeCurrent()-24*60*60*ye;
      if(type==1)if(TimeMonth(TimeCurrent())!=TimeMonth(timecurentnew))break;
      if(type==2)if(TimeYear(TimeCurrent())!=TimeYear(timecurentnew))break;
      //----------Íàõîäèì ïîñëåäíåå âîñêðåñåíüå(ïîñëåäíèé çàãðóæåíûé íà ñàéò êàëåíäàðü)
      int DayFile=TimeDay(timecurentnew-TimeDayOfWeek(timecurentnew)*86400);
      if(DayFile<10)string DF="0"+DayFile;
      else DF=DayFile;
      int MonthFile=TimeMonth(timecurentnew-TimeDayOfWeek(timecurentnew)*86400);
      if(MonthFile<10)string MF="0"+MonthFile;
      else MF=MonthFile;
      int YearFile=TimeYear(timecurentnew-TimeDayOfWeek(timecurentnew)*86400);
      string DateFile=MF+"-"+DF+"-"+YearFile;
      string FileName=DateFile+".csv";
      int handle;
      handle=FileOpen(FileName,FILE_CSV|FILE_READ,";");

      if(handle<0)
        {
         //-----Ñêà÷èâàåì êàëåíäàðü ---------------------------------------------------------------------   
         string url="http://www.dailyfx.com/files/Calendar-"+DateFile+".csv";
         //-------Ôóíêöèÿ ÷èòàåò èñõîäíûé êîä ñòðàíèöû ñàéòà â ñòðîêó------------------------------------
         if(!IsDllsAllowed())
           {
            Alert("Íåîáõîäèìî â íàñòðîéêàõ ðàçðåøèòü èñïîëüçîâàíèå DLL");
            return(0);
           }
         int rv = InternetAttemptConnect(0);
         if(rv != 0)
           {
            Alert("Îøèáêà ïðè âûçîâå InternetAttemptConnect()");
            return(0);
           }
         int hInternetSession=InternetOpenA("Microsoft Internet Explorer",
                                            0,"","",0);
         if(hInternetSession<=0)
           {
            Alert("Îøèáêà ïðè âûçîâå InternetOpenA()");
            return(0);
           }
         int hURL=InternetOpenUrlA(hInternetSession,
                                   url,"",0,0,0);
         if(hURL<=0)
           {
            Alert("Îøèáêà ïðè âûçîâå InternetOpenUrlA()");
            InternetCloseHandle(hInternetSession);
            return(0);
           }
         //------------------------------------------------------------------------      
         handle=FileOpen(FileName,FILE_CSV|FILE_WRITE,";");
         int dwBytesRead[1],N1,N2,N3,N4;
         string text="";
         string Str[10];
         for(int y=0;y<9;y++)Str[y]="";
         nom=0;
         int x=0;
         while(!IsStopped())
           {
            int cBuffer[256];
            bool bResult=InternetReadFile(hURL,cBuffer,1024,dwBytesRead);
            if(dwBytesRead[0]==0) break;
            for(int i=0; i<256; i++)
              {

               N1=cBuffer[i] & 0x000000FF;
               N2=cBuffer[i] >> 8 & 0x000000FF;
               N3=cBuffer[i] >> 16 & 0x000000FF;
               N4=cBuffer[i] >> 24 & 0x000000FF;
               if(N1!=44 && N1!=10)Str[x]=Str[x]+CharToStr(N1);
               else x++;
               if(N1==10){nom++;x=0;FileWrite(handle,Str[0],Str[1],Str[2],Str[3],Str[4],Str[5],Str[6],Str[7],Str[8]);for(y=0;y<9;y++)Str[y]="";}
               if((i*4)==dwBytesRead[0])break;
               if(N2!=44 && N2!=10)Str[x]=Str[x]+CharToStr(N2);
               else x++;
               if(N2==10){nom++;x=0;FileWrite(handle,Str[0],Str[1],Str[2],Str[3],Str[4],Str[5],Str[6],Str[7],Str[8]);for(y=0;y<9;y++)Str[y]="";}
               if((i*4)+1==dwBytesRead[0])break;
               if(N3!=44 && N3!=10)Str[x]=Str[x]+CharToStr(N3);
               else x++;
               if(N3==10){nom++;x=0;FileWrite(handle,Str[0],Str[1],Str[2],Str[3],Str[4],Str[5],Str[6],Str[7],Str[8]);for(y=0;y<9;y++)Str[y]="";}
               if((i*4)+2==dwBytesRead[0])break;
               if(N4!=44 && N4!=10)Str[x]=Str[x]+CharToStr(N4);
               else x++;
               if(N4==10){nom++;x=0;FileWrite(handle,Str[0],Str[1],Str[2],Str[3],Str[4],Str[5],Str[6],Str[7],Str[8]);for(y=0;y<9;y++)Str[y]="";}
               if((i*4)+3==dwBytesRead[0])break;
              }
           }
         InternetCloseHandle(hInternetSession);
         FileSeek(handle,0,SEEK_SET);
         FileWrite(handle,nom);
        }
      FileClose(handle);
      //-----------Çàíîñèì äàííûå èç ôàéëà â ìàññèâû.---------------------------------
      handle=FileOpen(FileName,FILE_CSV|FILE_READ,";");
      nom=StrToInteger(FileReadString(handle));
      string Hand;
      for(i=1;i<=8;i++)Hand=FileReadString(handle);
      string data,time,month,poyas,valuta;

      for(i=1;i<=nom;i++)
        {
         data=FileReadString(handle);
         time=FileReadString(handle);
         month=StringSubstr(data,4,3);
         if(month=="Jan") month="01";
         if(month=="Feb") month="02";
         if(month=="Mar") month="03";
         if(month=="Apr") month="04";
         if(month=="May") month="05";
         if(month=="Jun") month="06";
         if(month=="Jul") month="07";
         if(month=="Aug") month="08";
         if(month=="Sep") month="09";
         if(month=="Oct") month="10";
         if(month=="Nov") month="11";
         if(month=="Dec") month="12";
     if(time!="") TimeNews[i]=StrToTime(YearFile+"."+month+"."+StringSubstr(data,8,2)+" "+time)+GMT*3600;
     if(time=="") TimeNews[i]=0;
     
         text=FileReadString(handle);

         valuta=FileReadString(handle);
         if(valuta=="eur" ||valuta=="EUR")Valuta[i]="EUR";
         if(valuta=="usd" ||valuta=="USD")Valuta[i]="USD";
         if(valuta=="jpy" ||valuta=="JPY")Valuta[i]="JPY";
         if(valuta=="gbp" ||valuta=="GBP")Valuta[i]="GBP";
         if(valuta=="chf" ||valuta=="CHF")Valuta[i]="CHF";
         if(valuta=="cad" ||valuta=="CAD")Valuta[i]="CAD";
         if(valuta=="aud" ||valuta=="AUD")Valuta[i]="AUD";
         if(valuta=="nzd" ||valuta=="NZD")Valuta[i]="NZD";

         News[i]=FileReadString(handle);

         Vazn[i]=FileReadString(handle);
         if(Vazn[i]!="High" && Vazn[i]!="HIGH" && Vazn[i]!="Medium" && Vazn[i]!="MEDIUM" && Vazn[i]!="Low" && Vazn[i]!="LOW")Vazn[i]=FileReadString(handle);
         if(Vazn[i]!="High" && Vazn[i]!="HIGH" && Vazn[i]!="Medium" && Vazn[i]!="MEDIUM" && Vazn[i]!="Low" && Vazn[i]!="LOW")Vazn[i]=FileReadString(handle);
         if(Vazn[i]!="High" && Vazn[i]!="HIGH" && Vazn[i]!="Medium" && Vazn[i]!="MEDIUM" && Vazn[i]!="Low" && Vazn[i]!="LOW")Vazn[i]=FileReadString(handle);



         Actual[i]=FileReadString(handle);
         Prognoz[i]=FileReadString(handle);
         Prev[i]=FileReadString(handle);

         while(!IsStopped())
           {
            text=FileReadString(handle);
            if(FileIsLineEnding(handle))break;
           }
        }

      //------------Âûõîä èç ôóíêöèè--------------------------------------------------
      FileClose(handle);


      i=1;           color Col;

      //---Ðèñóåì ëèíèè íîâîñòåé íà ãðàôèêå--------------------------------------------
      if(LineCreate)
        {

         int na=0;
         int bartime[];
         ArrayResize(bartime,nom);
         for(int o=nom;o>=1;o--)
           {
            if(News[o]=="")continue;
            if(StringSubstr(Symbol(),0,3)!=Valuta[o] && StringSubstr(Symbol(),3,3)!=Valuta[o])continue;
            if((Vazn[o]=="High" || Vazn[o]=="HIGH") && HighNews==false)continue;
            if((Vazn[o]=="Medium" || Vazn[o]=="MEDIUM") && MediumNews==false)continue;
            if((Vazn[o]=="Low" || Vazn[o]=="LOW") && LowNews==false)continue;

            bartime[o]=TimeNews[o];
           }
         int predTime=-1;
         for(i=1;i<nom;i++)
           {

         if(News[i]=="")continue;
         if(TimeNews[i]==0)continue;
         
         // if (ObjectFind(News[i])==0)continue;
         if(StringSubstr(Symbol(),0,3)!=Valuta[i] && StringSubstr(Symbol(),3,3)!=Valuta[i])continue;
         if((Vazn[i]=="High" || Vazn[i]=="HIGH") && HighNews==false)continue;
         if((Vazn[i]=="Medium" || Vazn[i]=="MEDIUM") && MediumNews==false)continue;
         if((Vazn[i]=="Low" || Vazn[i]=="LOW") && LowNews==false)continue;
         if(Vazn[i]=="High"|| Vazn[i]=="HIGH")Col=high;
         if(Vazn[i]=="Medium"|| Vazn[i]=="MEDIUM")Col=medium;
         if(Vazn[i]=="Low"|| Vazn[i]=="LOW")Col=low;

         ObjectCreate("line"+News[i],OBJ_VLINE,0,TimeNews[i],0);
         ObjectSet("line"+News[i],OBJPROP_STYLE,1);
         ObjectSet("line"+News[i],OBJPROP_COLOR,Col);

         if(bartime[ArrayBsearch(bartime,TimeNews[i])]!=bartime[i]){na++;bartime[i]=-1; }else na=0;
         if(TimeDayOfWeek(TimeNews[i])!=predTime){na=0;predTime=TimeDayOfWeek(TimeNews[i]);}
         double raz=WindowPriceMax(0)-WindowPriceMin(0);
         ObjectCreate(News[i],OBJ_ARROW,0,0,0);
         ObjectSet(News[i],OBJPROP_TIME1,TimeNews[i]);
         ObjectSet(News[i],OBJPROP_PRICE1,High[iBarShift(Symbol(),0,TimeNews[i])]+na*raz/42);



         if(Vazn[i]=="Low"|| Vazn[i]=="LOW")ObjectSet(News[i],OBJPROP_ARROWCODE,140);
         if(Vazn[i]=="Medium"|| Vazn[i]=="MEDIUM")ObjectSet(News[i],OBJPROP_ARROWCODE,144);
         if(Vazn[i]=="High"|| Vazn[i]=="HIGH")ObjectSet(News[i],OBJPROP_ARROWCODE,149);
         ObjectSet(News[i],OBJPROP_COLOR,Col);
         ObjectSet(News[i],OBJPROP_STYLE,Style);
         ObjectSet(News[i],OBJPROP_RAY,false);

           }
        }


     }

   return(0);
  }
//+------------------------------------------------------------------+
 

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---