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

//|                                                    Calendar1.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"

   save, // ">;L:> A>E@0=8BL 2 D09;

   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;



struct structNew

  {

   datetime          newTime;       //2@5<O =>2>AB8

   ushort            newName[85];   //=0720=85 =>2>AB8

   int               newImportance; //206=>ABL =>2>AB8

  };

structNew stNew[];

int size = 0;

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

void OnStart()

  {

   ObjectsDeleteAll(0, "Obj");

   if(m_select == del)

      return;



   ChartSetInteger(0, CHART_SHOW_OBJECT_DESCR, descr);



   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] = CalendarValueHistory(values, date_from, date_to, NULL, Currencies[i]); //CalendarEventByCurrency(Currencies[i], events);

      if(events_count[i] > 0)

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

            if(CalendarEventById(values[l].event_id, events))

               if((events.importance == CALENDAR_IMPORTANCE_LOW && LOW) ||

                  (events.importance == CALENDAR_IMPORTANCE_MODERATE && MODERATE) ||

                  (events.importance == CALENDAR_IMPORTANCE_HIGH && HIGH))

                 {

                  if(_Print)

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

                  if(m_select == save)

                    {

                     ArrayResize(stNew, size + 1);

                     stNew[size].newTime = values[l].time;

                     StringToShortArray(events.name, stNew[size].newName);

                     stNew[size].newImportance = events.importance;

                     size++;

                    }

                  else

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

                 }

     }

   if(save)

      if(FileSave(_Symbol, stNew, FILE_COMMON))

         Print("AB>@8O =>2>AB59 2K3@C65=0 2 D09;.");

  }

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

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);

  }

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

//>4 4;O 2AB02:8 2 A>25B=8: 4;O @01>BK 2 B5AB5@5

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

void Tester()

  {

   FileLoad(_Symbol, stNew, FILE_COMMON);

   int aSize = ArraySize(stNew);

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

      Print((string)stNew[i].newTime + "  " + ShortArrayToString(stNew[i].newName) + "  " + EnumToString((ENUM_CALENDAR_EVENT_IMPORTANCE)stNew[i].newImportance));

  }

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

Comments