Trying to get Calendars Events but showing Error

 

I wrote the code below to get news from calendar of certain symbols but I am getting Error:

Error! Failed to get events of country_code = EUR 

Thanks in advance for your help

const  input  OPTION                   SendNewsAlerts           = Yes;                                               //Send News Alerts:
const  input  string                   Currencies_Check         = "EUR,USD";                                         //Symbols to Check(Max 2 Symbols)
const  input  int                      NewsBefore               = 30;                                                //Alert Before News
const  input  OPTION                   LowNewsAlerts            = Yes;                                               //Send Low News Alerts:
const  input  OPTION                   MediumNewsAlerts         = Yes;                                               //Send Medium News Alerts:
const  input  OPTION                   HighNewsAlerts           = Yes;                                               //Send High News Alerts:


//+------------------------------------------------------------------+  
void NewsManager()
   {
      if(SendNewsAlerts == No)return;
      
      string   symbolsarray[];
      int      total = StringSplit(Currencies_Check,',',symbolsarray); 
      MqlCalendarValue values1[]; 
      MqlCalendarValue values2[]; 
      
      datetime date_from  = StringToTime("2024.01.01 [00:00]");  
      datetime date_to    = 0;  
      if(!CalendarValueHistory(values1, date_from, date_to, symbolsarray[0])) 
        { 
            PrintFormat("Error! Failed to get events for country_code=%s", symbolsarray[0]); 
            PrintFormat("Error code: %d", GetLastError()); 
            return; 
        } 
      if(ArraySize(symbolsarray) > 1)
         {
            if(!CalendarValueHistory(values2, date_from, date_to, symbolsarray[1])) 
              { 
                  PrintFormat("Error! Failed to get events for country_code=%s", symbolsarray[1]); 
                  PrintFormat("Error code: %d", GetLastError()); 
                  return; 
              } 
         }
      
      
      AdjustedCalendarValue values_adjusted_1[]; 
      AdjustedCalendarValue values_adjusted_2[]; 
      
      int total1   = ArraySize(values1); 
      int total2   = ArraySize(values2); 
      
      ArrayResize(values_adjusted_1, total1); 
      ArrayResize(values_adjusted_2, total2); 
      
      for(int i = 0; i < total1; i++) 
        { 
         values_adjusted_1[i].id            = values1[i].id; 
         values_adjusted_1[i].event_id      = values1[i].event_id; 
         values_adjusted_1[i].time          = values1[i].time; 
         values_adjusted_1[i].period        = values1[i].period; 
         values_adjusted_1[i].revision      = values1[i].revision; 
         values_adjusted_1[i].impact_type   = values1[i].impact_type; 
         values_adjusted_1[i].actual_value  = values1[i].GetActualValue(); 
         values_adjusted_1[i].prev_value    = values1[i].GetPreviousValue(); 
         values_adjusted_1[i].revised_prev_value = values1[i].GetRevisedValue(); 
         values_adjusted_1[i].forecast_value = values1[i].GetForecastValue(); 
        } 
      
      for(int i = 0; i < total2; i++) 
        { 
         values_adjusted_2[i].id            = values2[i].id; 
         values_adjusted_2[i].event_id      = values2[i].event_id; 
         values_adjusted_2[i].time          = values2[i].time; 
         values_adjusted_2[i].period        = values2[i].period; 
         values_adjusted_2[i].revision      = values2[i].revision; 
         values_adjusted_2[i].impact_type   = values2[i].impact_type; 
         values_adjusted_2[i].actual_value  = values2[i].GetActualValue(); 
         values_adjusted_2[i].prev_value    = values2[i].GetPreviousValue(); 
         values_adjusted_2[i].revised_prev_value = values2[i].GetRevisedValue(); 
         values_adjusted_2[i].forecast_value = values2[i].GetForecastValue(); 
        } 
      
      string newsmessage1  = "---NEWS DASHBOARD---" + "\n";
      string newsmessage2  = "";
      int    number        = 1;
      for(int i = 0; i < ArraySize(values_adjusted_1); i++) 
        {
            if(TimeCurrent() + (NewsBefore * 60) < values_adjusted_1[i].time)continue;
            MqlCalendarEvent event;
            if(CalendarEventById(values_adjusted_1[i].event_id,event))
              {
                  newsmessage2 += IntegerToString(number) + ". " + event.name + "\n";
                  number++;
              }
        }
      for(int i = 0; i < ArraySize(values_adjusted_2); i++) 
        {
            if(TimeCurrent() + (NewsBefore * 60) < values_adjusted_2[i].time)continue;
            MqlCalendarEvent event;
            if(CalendarEventById(values_adjusted_2[i].event_id,event))
              {
                  newsmessage2 += IntegerToString(number) + ". " + event.name + "\n";
                  number++;
              }
        }
      
      if(newsmessage2 == "")newsmessage2  = "No News!!";
      newsmessage1        += newsmessage2;
      Comment(newsmessage1);
   }
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
Fernando Carreiro #:
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893

No problem Fernando thanks for the correction, do you have an answer?

 
Vincent Kimathi Baariu #:

No problem Fernando thanks for the correction, do you have an answer?

Vincent Kimathi Baariu:

I wrote the code below to get news from calendar of certain symbols but I am getting Error:

Error! Failed to get events of country_code = EUR 

Thanks in advance for your help

Haven't tested your code,

But from a quick-look I think this might be your issue-

You are passing the 'currency' as the 'country code' input parameter of the 'CalendarValueHistory' function.

 
AMI289 #:

Haven't tested your code,

But from a quick-look I think this might be your issue-

You are passing the 'currency' as the 'country code' input parameter of the 'CalendarValueHistory' function.

How should it be?

 
Vincent Kimathi Baariu #: How should it be?

Please read the documentation ... Documentation on MQL5: Economic Calendar / CalendarValueHistory

int  CalendarValueHistory(
   MqlCalendarValue&  values[],              // array for value descriptions 
   datetime           datetime_from,         // left border of a time range
   datetime           datetime_to=0          // right border of a time range
   const string       country_code=NULL,     // country code name (ISO 3166-1 alpha-2)
   const string       currency=NULL          // country currency code name 
   );

The 4th parameter is the country code, and the 5th parameter is the currency.

Documentation on MQL5: Economic Calendar / CalendarValueHistory
Documentation on MQL5: Economic Calendar / CalendarValueHistory
  • www.mql5.com
CalendarValueHistory - Economic Calendar - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5