Author: Copyright 2020, MetaQuotes Software Corp.

This script is a specialized tool designed for the MetaTrader 5 platform that automates the process of identifying and visualizing economic calendar events directly on your trading charts. Instead of requiring you to manually check external websites or news feeds, it pulls this data automatically based on the specific currency pair you are currently trading.

Core Functionality

The primary purpose of the script is to "map" important economic news (like interest rate decisions, GDP reports, or employment data) onto your price chart. It looks at a specific date range—which you can customize in the settings—and retrieves all relevant events for the base and profit currencies of your chosen asset.

Key Features & Logic:

  • Smart Filtering: You have full control over what information is displayed. You can toggle whether you want to see "High," "Moderate," or "Low" importance events. This helps clear out market noise so you only see the data that actually impacts price movement.
  • Visual Customization: The script allows you to choose how these events appear on your screen:
    • Lines: Draws a vertical line at the exact moment an event occurs.
    • Events: Places a specific marker or icon (ideal for non-linear data).
    • Styling: You can adjust the width of the lines, the color coding (e.g., Red for High importance, Blue for Moderate, Green for Low), and even the visual style (solid, dashed, etc.).
  • Data Persistence (Save Mode): One of the more advanced features is the ability to save your results. If enabled, the script can record the gathered events into a local file. This means the data can be stored and potentially recalled or audited later without re-scanning the live calendar.
  • Automatic Recognition: The logic identifies the currency pair automatically. For example, if you are looking at EURUSD, it will intelligently seek out news relevant to both the Eurozone and the United States.

How it Works for the User:

When you run the script, it performs a "sweep" of the economic calendar within your specified dates. It then proceeds to draw the markers on your chart. If an event already exists on the chart, the script is smart enough to check its importance; it will only update the visual if the new information is more significant than what is already displayed, preventing your chart from becoming cluttered with redundant information.

Essentially, this tool transforms your trading chart into a proactive news map, ensuring you are always aware of upcoming economic milestones without ever having to leave your trading platform.

3 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