Author: Copyright 2019, MetaQuotes Software Corp.
0 Views
0 Downloads
0 Favorites
News
ÿþ//+------------------------------------------------------------------+

//|                                                         News.mq5 |

//|                        Copyright 2019, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2019, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property indicator_chart_window

//#property indicator_separate_window



datetime _order_;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping



//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

//int OnDeinit()

//  {

//   EventDelete();

//   return(INIT_SUCCEEDED);

//  }

//--- 2E>4=K5 ?0@0<5B@K A:@8?B0 

input string          InpName="Event";    // <O A>1KB8O 

input int             InpDate=25;         // 0B0 A>1KB8O 2 % 

input string          InpText="Text";     // "5:AB A>1KB8O 

input color           InpColor=clrRed;    // &25B A>1KB8O 

input int             InpWidth=1;         //  07<5@ B>G:8 ?@8 2K45;5=88 

input bool            InpBack=false;      // !>1KB85 =0 704=5< ?;0=5 

input bool            InpSelection=false; // K45;8BL 4;O ?5@5<5I5=89 

input bool            InpHidden=true;     // !:@KB 2 A?8A:5 >1J5:B>2 

input long            InpZOrder=0;        // @8>@8B5B =0 =060B85 <KHLN 

//+------------------------------------------------------------------+ 

//| !>7405B >1J5:B "!>1KB85" =0 3@0D8:5                              | 

//+------------------------------------------------------------------+ 

bool EventCreate(const string          name="Event",// 8<O A>1KB8O 

                 const int             sub_window=1,    // =><5@ ?>4>:=0 

                 const string          text="Text",     // B5:AB A>1KB8O 

                 datetime              time=0,          // 2@5<O 

                 const color           clr=clrMagenta,// F25B 

                 const int             width=1,// B>;I8=0 B>G:8 ?@8 2K45;5=88 

                 const bool            back=true,// =0 704=5< ?;0=5 

                 const bool            selection=false, // 2K45;8BL 4;O ?5@5<5I5=89 

                 const bool            hidden=true,     // A:@KB 2 A?8A:5 >1J5:B>2 

                 const long            z_order=0)       // ?@8>@8B5B =0 =060B85 <KHLN 

  {

//--- 5A;8 2@5<O =5 7040=>, B> A>7405< >1J5:B =0 ?>A;54=5< 10@5 

   if(!time)

      time=TimeCurrent();

//--- A1@>A8< 7=0G5=85 >H81:8 

   ResetLastError();

//--- A>74048< >1J5:B "!>1KB85" 

//if(!ObjectCreate(0,name,OBJ_EVENT,sub_window,time,0))

   if(!ObjectCreate(0,name,OBJ_EVENT,1,time,0))

     {

      //Print(__FUNCTION__,": =5 C40;>AL A>740BL >1J5:B \"!>1KB85\"! >4 >H81:8 = ",GetLastError(), string(time));

      return(false);

     }



//--- CAB0=>28< B5:AB A>1KB8O 

   ObjectSetString(0,name,OBJPROP_TEXT,string(time)+"  "+text);

//--- CAB0=>28< F25B 

   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);

//--- CAB0=>28< B>;I8=C B>G:8 ?@82O7:8, 5A;8 >1J5:B 2K45;5= 

   ObjectSetInteger(0,name,OBJPROP_WIDTH,width);

//--- >B>1@078< =0 ?5@54=5< (false) 8;8 704=5< (true) ?;0=5 

   ObjectSetInteger(0,name,OBJPROP_BACK,back);

//--- 2:;NG8< (true) 8;8 >B:;NG8< (false) @568< ?5@5<5I5=8O A>1KB8O <KHLN 

   ObjectSetInteger(0,name,OBJPROP_SELECTABLE,selection);

   ObjectSetInteger(0,name,OBJPROP_SELECTED,selection);

//--- A:@>5< (true) 8;8 >B>1@078< (false) 8<O 3@0D8G5A:>3> >1J5:B0 2 A?8A:5 >1J5:B>2 

   ObjectSetInteger(0,name,OBJPROP_HIDDEN,hidden);

//--- CAB0=>28< ?@8>@8B5B =0 ?>;CG5=85 A>1KB8O =060B8O <KH8 =0 3@0D8:5 

   ObjectSetInteger(0,name,OBJPROP_ZORDER,z_order);

//--- CA?5H=>5 2K?>;=5=85 

   return(true);

  }

//+------------------------------------------------------------------+ 

//| #40;O5B >1J5:B "!>1KB85"                                         | 

//+------------------------------------------------------------------+ 

bool EventDelete(const long   chart_ID=0,// ID 3@0D8:0 

                 const string constname="Event") // 8<O A>1KB8O 

  {

//--- A1@>A8< 7=0G5=85 >H81:8 

   ResetLastError();

////--- C40;8< >1J5:B 

//   if(!ObjectDelete(chart_ID,name))

//     {

//      Print(__FUNCTION__,

//            ": =5 C40;>AL C40;8BL >1J5:B \"!>1KB85\"! >4 >H81:8 = ",GetLastError());

//      return(false);

//     };



   int nL=ObjectsTotal(0,0,OBJ_EVENT);

   string name;

   for(int n=nL-1; n>=0; n--) // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! B>;L:> ?> C1K20=8N

     {

      name=ObjectName(0,n,0,OBJ_EVENT);

      if(ObjectGetInteger(0,name,OBJPROP_TYPE)!=OBJ_EVENT)

         continue;

      int nch= StringFind(name,constname);

      if(nch == 0)

         ObjectDelete(0,name);

     };



//--- CA?5H=>5 2K?>;=5=85 

   return(true);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const int begin,

                const double &price[])

  {



   if(_order_!=iTime(NULL,_Period,1))

     {

      _order_=iTime(NULL,_Period,1);



      //string EU_code="EU";

      //--- ?>;CG8< 2A5 7=0G5=8O A>1KB89 ?> 2@>?59A:><C A>N7C 

      MqlCalendarValue values[];

      MqlCalendarEvent valuesE[];

      //--- 704048< 3@0=8FK 480?07>=0, 87 :>B>@>3> 15@5< A>1KB8O 

      datetime date_from=D'01.01.2019';  // 15@5< 2A5 A>1KB8O A 2018 3>40 

      datetime date_to=D'31.08.2020';                // 0 >7=0G05B 2A5 8725AB=K5 A>1KB8O, 4065 B5, GB> =5 =0ABC?8;8 5I5  



      MqlDateTime time_now;

      datetime candle_time=TimeLocal();

      TimeToStruct(candle_time,time_now);  // change time to struct

      int _god=(time_now.year);

      int _mon=(time_now.mon);

      if(_mon==1)

        {

         _mon=12;

         _god=_god-1;

        }

      else

        {

         _mon=_mon-1;

        };

      //date_from=StringToTime(string(_god)+"."+string(_mon)+".01 00:00");



      //Print(date_from);



      if(time_now.year>2018)

        {



        };



      //--- 70?@>A8< 8AB>@8N A>1KB8O ?> 2@>?59A:><C A>N7C A 2018 3>40 

      if(CalendarValueHistory(values,date_from,date_to,""))

        {

         ////////////         PrintFormat(">;CG5=K 7=0G5=8O A>1KB89 ?> country_code=%s: %d",

         ////////////                     EU_code,ArraySize(values));

         ////////////         //--- C<5=LH8< @07<5@ <0AA820 4;O 2K2>40 2 C@=0; 

         ////////////         //ArrayResize(values,100);

         ////////////

         ////////////         int values_count=CalendarValueHistory(values,date_from,date_to,EU_code);

         ////////////         //--- ?@>945< ?> =0945==K< 7=0G5=8O< A>1KB89 

         ////////////         if(values_count>0)

         ////////////           {

         ////////////            PrintFormat(">;8G5AB2> 7=0G5=89 4;O A>1KB89 /?>=88: %d",values_count);

         ////////////            //--- C40;8< 2A5 "?CABK5" 7=0G5=8O (actual_value==-9223372036854775808)        

         ////////////            for(int i=values_count-1;i>=0;i--)

         ////////////              {

         ////////////               if(values[i].actual_value==-9223372036854775808)

         ////////////                  ArrayRemove(values,i,1);

         ////////////              }

         ////////////            PrintFormat(">;8G5AB2> 7=0G5=89 ?>A;5 C40;5=8O ?CABKE: %d",ArraySize(values));

         ////////////           };

         EventDelete();

         int values_count=ArraySize(values);

         //Print(values_count);

         //---C40;8< 2A5 "?CABK5" 7=0G5=8O(actual_value==-9223372036854775808)

         //for(int i=values_count-1;i>=0;i--)

         //  {

         //   if(values[i].actual_value==-9223372036854775808)

         //      ArrayRemove(values,i,1);

         //  };

         values_count=ArraySize(values);

         //Print(values_count);



         for(int i=values_count-1;i>=0;i--)

           {

            MqlCalendarEvent event;

            ulong event_id=values[i].event_id;

            if(CalendarEventById(event_id,event))

              {

               if(event.importance==CALENDAR_IMPORTANCE_LOW || event.importance==CALENDAR_IMPORTANCE_NONE)

                 {

                  EventCreate("Event "+string(values[i].time),0,event.name,values[i].time,clrGreen,1,true,false,true,0);

                 }

               else if(event.importance==CALENDAR_IMPORTANCE_MODERATE)

                 {

                  EventCreate("Event "+string(values[i].time),0,event.name,values[i].time,clrDarkOrange,1,true,false,true,0);

                 }

               else if(event.importance==CALENDAR_IMPORTANCE_HIGH)

                 {

                  EventCreate("Event "+string(values[i].time),0,event.name,values[i].time,clrMediumVioletRed,1,true,false,true,0);

                 }



               ;

              };

           };



         //         for(int i=values_count-1;i>=0;i--)

         //           {

         //            MqlCalendarEvent event;

         //            ulong event_id=values[i].event_id;

         //            if(CalendarEventById(event_id,event))

         //              {

         //               if(event.importance==CALENDAR_IMPORTANCE_MODERATE)

         //                 {

         //                  EventCreate("Event "+string(values[i].time),0,event.name,values[i].time,clrDarkOrange,1,true,false,true,0);

         //                 };

         //              };

         //           };

         //

         //         for(int i=values_count-1;i>=0;i--)

         //           {

         //            MqlCalendarEvent event;

         //            ulong event_id=values[i].event_id;

         //            if(CalendarEventById(event_id,event))

         //              {

         //               if(event.importance==CALENDAR_IMPORTANCE_HIGH)

         //                 {

         //                  EventCreate("Event "+string(values[i].time),0,event.name,values[i].time,clrMediumVioletRed,1,true,false,true,0);

         //                 };

         //              };

         //           };

         //--- 2K2545< 7=0G5=8O A>1KB89 2 C@=0; 

         //ArrayPrint(values);



         ////////////////         values_count=CalendarValueHistory(values,date_from,date_to,EU_code);

         ////////////////         //--- ?@>945< ?> =0945==K< 7=0G5=8O< A>1KB89 

         ////////////////         if(values_count>0)

         ////////////////           {

         ////////////////            PrintFormat(">;8G5AB2> 7=0G5=89 4;O A>1KB89 /?>=88: %d",values_count);

         ////////////////            //--- C40;8< 2A5 "?CABK5" 7=0G5=8O (actual_value==-9223372036854775808)        

         ////////////////            for(int i=values_count-1;i>=0;i--)

         ////////////////              {

         ////////////////

         ////////////////               

         ////////////////               MqlCalendarEvent events[];

         ////////////////               int events_count=CalendarEventByCountry(EU_code,events);

         ////////////////               MqlCalendarEvent event;

         ////////////////               //ulong event_id=events[events_count-1].id;

         ////////////////               ulong event_id=values[i].event_id;

         ////////////////               if(CalendarEventById(event_id,event))

         ////////////////                 {

         ////////////////                  MqlCalendarCountry country;

         ////////////////                  CalendarCountryById(event.country_id,country);

         ////////////////                  PrintFormat(">;CG5=> >?8A0=8O A>1KB8O A event_id=%d",event_id);

         ////////////////                  Print(values[i].time);

         ////////////////                  PrintFormat("CB@0=0: %s (:>4 AB@0=K = %d)",country.name,event.country_id);

         ////////////////                  PrintFormat("<O A>1KB8O: %s",event.name);

         ////////////////                  PrintFormat(">4 A>1KB8O: %s",event.event_code);

         ////////////////                  PrintFormat("06=>ABL A>1KB8O: %s",EnumToString((ENUM_CALENDAR_EVENT_IMPORTANCE)event.importance));

         ////////////////                  PrintFormat(""8? A>1KB8O: %s",EnumToString((ENUM_CALENDAR_EVENT_TYPE)event.type));

         ////////////////                  PrintFormat("!5:B>@ A>1KB8O: %s",EnumToString((ENUM_CALENDAR_EVENT_SECTOR)event.sector));

         ////////////////                  PrintFormat("5@8>48G=>ABL A>1KB8O: %s",EnumToString((ENUM_CALENDAR_EVENT_FREQUENCY)event.frequency));

         ////////////////                  PrintFormat(" 568< 2KE>40 A>1KB8O: %s",EnumToString((ENUM_CALENDAR_EVENT_TIMEMODE)event.time_mode));

         ////////////////                  PrintFormat("48=8F0 87<5@5=8O 7=0G5=8O: %s",EnumToString((ENUM_CALENDAR_EVENT_UNIT)event.unit));

         ////////////////                  PrintFormat(">;8G5AB2> 7=0:>2 ?>A;5 70?OB>9: %d",event.digits);

         ////////////////                  PrintFormat("=>68B5;L 7=0G5=8O: %s",EnumToString((ENUM_CALENDAR_EVENT_MULTIPLIER)event.multiplier));

         ////////////////                  PrintFormat("URL 8AB>G=8:0: %s",event.source_url);

         ////////////////                 }

         ////////////////               else

         ////////////////                  PrintFormat("5 C40;>AL ?>;CG8BL >?8A0=85 A>1KB8O 4;O event_d=%s, >H81:0 %d",

         ////////////////                              event_id,GetLastError());

         ////////////////

         ////////////////              }

         ////////////////            PrintFormat(">;8G5AB2> 7=0G5=89 ?>A;5 C40;5=8O ?CABKE: %d",ArraySize(values));

         ////////////////           };







        }

      else

        {

         //PrintFormat("H81:0! 5 C40;>AL ?>;CG8BL A>1KB8O ?> AB@0=5 country_code=%s",EU_code);

         PrintFormat(">4 >H81:8: %d",GetLastError());



        };



     };

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

Comments