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

//|                                                     Calendar.mq5 |

//|                                  Copyright 2021, MetaQuotes Ltd. |

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

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

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

#property link      "https://www.mql5.com/ru/users/s22aa"

#property version   "1.00"

#property script_show_inputs



input datetime date_from = D'01.06.2021';  //! 40BK

input datetime date_to   = D'01.07.2021';  //> 40BC

input group"-------->:07K20BL =>2>AB8---------"

input bool  HIGH            = true;        //KA>:0O 206=>ABL

input color high            = clrRed;      //KA>:0O 206=>ABL

input bool  MODERATE        = true;        //!@54=OO 206=>ABL

input color moderate        = clrBlue;     //!@54=OO 206=>ABL

input bool  LOW             = true;        //87:0O 206=>ABL

input color low             = clrGreen;    //87:0O 206=>ABL

input group"-----------------------------------"

enum select

  {

   line, // 1J5:BK "5@B8:0;L=K5 ;8=88"

   event,// 1J5:BK "!>1KB85"

   del   // #40;8BL 2A5 >1J5:BK

  };

input select m_select       = line;        //8=88 8;8 !>1KB85

input int    width          = 2;           //">;I8=0 ;8=89

input ENUM_LINE_STYLE style = STYLE_SOLID; //!B8;L ;8=9

input bool   descr          = true;        //>:07K20BL >?8A0=85 >1J5:B>2 

input bool  _Print          = false;       //5G0BL 2 6C@=0;

datetime _date_to;

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

void OnStart()

  {

   ObjectsDeleteAll(0, "Obj");

   if(m_select == del)

      return;

   ChartSetInteger(0, CHART_SHOW_OBJECT_DESCR, descr);

   _date_to = date_to;

   if(_date_to < TimeCurrent())

      _date_to = TimeCurrent() + PeriodSeconds(PERIOD_CURRENT);



   string Currencies[2];

   Currencies[0] = SymbolInfoString(_Symbol, SYMBOL_CURRENCY_BASE);

   Currencies[1] = SymbolInfoString(_Symbol, SYMBOL_CURRENCY_PROFIT);

   MqlCalendarValue values[];

   MqlCalendarEvent events[];

   int events_count[2];



   for(int i = 0; i < 2; i++)

     {

      events_count[i] = CalendarEventByCurrency(Currencies[i], events);

      if(events_count[i] > 0)

        {

         for(int l = 0; l < events_count[i]; l++)

           {

            if((events[l].importance == CALENDAR_IMPORTANCE_LOW && LOW) ||

               (events[l].importance == CALENDAR_IMPORTANCE_MODERATE && MODERATE) ||

               (events[l].importance == CALENDAR_IMPORTANCE_HIGH && HIGH))



               if(CalendarValueHistoryByEvent(events[l].id, values, date_from, _date_to))

                  for(int j = 0; j < ArraySize(values); j++)

                    {

                     if(_Print)

                        Print((string)values[j].time + "  " + events[l].name + "  " + EnumToString(events[l].importance));

                     Create(values[j].time, events[l].name, events[l].importance);

                    }

           }

        }

     }

  }

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

bool Create(datetime time = 0, const string tooltip = "", const int importance = 3)

  {

   ResetLastError();

   if(!time)

      time = TimeCurrent();

   string name = "Obj" + (string)time;

   color clr = importance == 3 ? high : importance == 2 ? moderate : low;

   long _clr_;

   if(ObjectGetInteger(0, name, OBJPROP_COLOR, 0, _clr_)) // 5A;8 A>1KB85 C65 =0@8A>20=>, ?@>25@O5< 206=>ABL 8 5A;8 206=>ABL <5=LH5, B> =5 ?5@5@8A>2K205<

     {

      long Get_importance = _clr_ == high ? 3 : _clr_ == moderate ? 2 : 1;

      if(Get_importance > importance)

         return(true);

     }

   if(!ObjectCreate(0, name, m_select == line ? OBJ_VLINE : OBJ_EVENT, 0, time, 0))

     {

      Print(__FUNCTION__,

            ": =5 C40;>AL A>740BL 25@B8:0;L=CN ;8=8N! >4 >H81:8 = ", GetLastError());

      return(false);

     }

   ObjectSetInteger(0, name, OBJPROP_COLOR, clr);

   ObjectSetString(0, name, OBJPROP_TEXT, tooltip);

   ObjectSetString(0, name, OBJPROP_TOOLTIP, tooltip);

   ObjectSetInteger(0, name, OBJPROP_WIDTH, width);

   ObjectSetInteger(0, name, OBJPROP_STYLE, style);



   return(true);

  }

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

Comments