How to Identify the Correct Field Name for Event Time in MqlCalendarEvent

 

Hello everyone,

I’m working with the MetaTrader 5 economic calendar functions and encountering an issue with the  MqlCalendarEvent  structure. Specifically, I’m trying to access the event time, but I’m getting the following error:

'time' - undeclared identifier

I’ve also tried using   time_utc  and  time_start , , , but none of these field names seem to work. Could someone please help me identify the correct field name for the event time in the  MqlCalendarEvent  structure?

Here’s the relevant part of my code:

bool IsHighImpactNews()
{
    datetime currentTime = TimeCurrent();
    
    for (int i = 0; i < ArraySize(calendarEvents); i++)
    {
        MqlCalendarEvent event = calendarEvents[i]; // Store current event

        // Only check HIGH impact news (Importance = 3)
        if (event.importance < CALENDAR_IMPORTANCE_HIGH) continue;

        // Get country details
        MqlCalendarCountry countryInfo;
        if (!CalendarCountryById(event.country_id, countryInfo))
        {
            Print("Error retrieving country info for event ID: ", event.id);
            continue;
        }

        // Check if the event affects USD (United States)
        string countryLower = StringToLower(countryInfo.name);
        if (StringFind(countryLower, "united states") != -1 || StringFind(countryLower, "us") != -1)
        {
            datetime eventTime = event.time; // Use the correct field for event time

            // Check if news is within the buffer window
            if (currentTime >= eventTime - newsEventBufferMinutes * 60 &&
                currentTime <= eventTime + newsEventBufferMinutes * 60)
            {
                Print("High-impact USD news detected: ", event.name);
                return true;
            }
        }
    }
    return false;
}

What I’ve Tried So Far:

  1. I’ve tried using  event.time ,  event.time_utc , and  event.time_start , but none of these field names are recognized.

  2. I’ve checked the official MetaTrader 5 documentation, but it doesn’t explicitly mention the field names for  MqlCalendarEvent .

Questions:

  1. What is the correct field name for the event time in the  MqlCalendarEvent  structure?

  2. Is there a way to inspect the  MqlCalendarEvent  structure definition to find the correct field names?

  3. Has anyone else encountered this issue, and how did you resolve it?

Any help or guidance would be greatly appreciated. Thank you in advance!

Best regards,

 

Everything (including all the fields) is documented - https://www.mql5.com/en/docs/constants/structures/mqlcalendar#mqlcalendarevent

You probably want MqlCalendarValue.

Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Economic Сalendar structures
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Economic Сalendar structures
  • www.mql5.com
This section describes the structures for working with the economic calendar available directly in the MetaTrader platform. The economic calendar...
 
Asif nawab:

Hello everyone,

I’m working with the MetaTrader 5 economic calendar functions and encountering an issue with the  MqlCalendarEvent  structure. Specifically, I’m trying to access the event time, but I’m getting the following error:

'time' - undeclared identifier

I’ve also tried using   time_utc  and  time_start , , , but none of these field names seem to work. Could someone please help me identify the correct field name for the event time in the  MqlCalendarEvent  structure?

Here’s the relevant part of my code:

What I’ve Tried So Far:

  1. I’ve tried using  event.time ,  event.time_utc , and  event.time_start , but none of these field names are recognized.

  2. I’ve checked the official MetaTrader 5 documentation, but it doesn’t explicitly mention the field names for  MqlCalendarEvent .

Questions:

  1. What is the correct field name for the event time in the  MqlCalendarEvent  structure?

  2. Is there a way to inspect the  MqlCalendarEvent  structure definition to find the correct field names?

  3. Has anyone else encountered this issue, and how did you resolve it?

Any help or guidance would be greatly appreciated. Thank you in advance!

Best regards,

Consult this code 

The way you approach this is scan the daily events by calling all MqlCalendarValues for the day.

You need to find the importance so you then request MqlCalendarEvent with the event id received in the value to get the type and name and importance

And then you request the event country with the country id you received in the calendar event structure to get the currency and the coutry name .

An example : 

int OnInit()
  {
  EventSetMillisecondTimer(55);
  return(INIT_SUCCEEDED);
  }
void OnTick(){}
void OnTimer()
  {
  Comment("WAIT...");
  EventKillTimer();
  fillEvents(TimeCurrent(),EVENTS_LIST);
  Comment("DONE...");
  //store the events in a file to read later 
  //      or keep the list and read it during the day
  int f=FileOpen("calendar.txt",FILE_WRITE|FILE_TXT);
  if(f!=INVALID_HANDLE){
    for(int e=0;e<ArraySize(EVENTS_LIST);e++){
    string row="["+TimeToString(EVENTS_LIST[e].time,TIME_DATE|TIME_MINUTES|TIME_SECONDS)+"]";
           row+=" "+EVENTS_LIST[e].title+" {"+EVENTS_LIST[e].currency+"} {"+EVENTS_LIST[e].country+"}";
           row+=" Impact("+IntegerToString(EVENTS_LIST[e].impact)+")\n";
           FileWriteString(f,row);
    }
    FileClose(f);
    }
  }
/*
First you gotta request the values and store them in a "list"
the calendar structure has 3 components to each entry :
> country
> event
> value

You are only interested in :
    Title
    Country
    Time
    Impact
so let's create a structure for that
*/
class calendarEntry{
         public:
  string title,country,currency;
datetime time; 
    char impact;
         calendarEntry(void){reset();}
        ~calendarEntry(void){reset();}
    void reset(){
         impact=-1;
         time=0;
         title="";
         country="";
         currency="";
         }
};

/*
then we need a list of the above to keep track of them
*/

calendarEntry EVENTS_LIST[];

/* now we need a way to search for todays events 
   we will give the function a data and a list
   and it will fill it , once per day.
   
*/
void fillEvents(datetime for_day,calendarEntry &list[]){
/* the &list[] here means the function will accept a list 
   and change it , we will send the EVENTS_LIST here when we call the function
   But first , the most certain certainty besides taxes is that 
   the user will botch the time parameter.
   So we have to flatten it to reflect the start of the day.
   The timestamp is in seconds 
   one day has 86400 seconds
   So divide by 86400 , floor it and multiply again 
*/
datetime flat=(datetime)((long)(MathFloor(((double)for_day)/((double)86400)))*86400);
//neat
//next we empty the list 
  ArrayFree(list);//this erases all items from the name of the list we sent here
  //so if we send EVENTS_LIST it will empty it first
/* Call the mql site and ask for todays events , ask for values 
   we need a receiver for the values here , the trick is 
   events for mq means the type of the event
   and values for mq means the data of the event
*/
   ResetLastError();
   MqlCalendarValue receiver[];
   if(CalendarValueHistory(receiver,flat,0)>0){
   Print("Received "+IntegerToString(ArraySize(receiver))+" for "+TimeToString(flat,TIME_DATE|TIME_MINUTES|TIME_SECONDS));
   //resize our list to the size of the receiver
   ArrayResize(list,ArraySize(receiver),0);
   //now loop into these events
     for(int e=0;e<ArraySize(receiver);e++){
        //get the time 
          list[e].time=receiver[e].time;
        //get the event  
          /*
          we request more info about the event 
          using the event id provided to get the title
          and country id of this event...
          Place it in eventTypeReceiver 
          */
          MqlCalendarEvent eventTypeReceiver={};
          if(CalendarEventById(receiver[e].event_id,eventTypeReceiver)){
            list[e].title=eventTypeReceiver.name;
            ENUM_CALENDAR_EVENT_IMPORTANCE imp=eventTypeReceiver.importance;
            list[e].impact=0;
                 if(imp==CALENDAR_IMPORTANCE_LOW){list[e].impact=1;}
            else if(imp==CALENDAR_IMPORTANCE_MODERATE){list[e].impact=2;}
            else if(imp==CALENDAR_IMPORTANCE_HIGH){list[e].impact=3;}
            //get the country
              /*
              we request more info about the event country
              using the country id provided to get
              the country name and currency this event 
              is about...
              Place it in eventCountryReceiver
              */
              MqlCalendarCountry eventCountryReceiver={};
              if(CalendarCountryById(eventTypeReceiver.country_id,eventCountryReceiver)){
                list[e].country=eventCountryReceiver.name;
                list[e].currency=eventCountryReceiver.currency;
                }
            }
        }
   }else{
   Print("Cannot retrieve event data for "+TimeToString(flat,TIME_DATE|TIME_MINUTES|TIME_SECONDS)+" error#"+IntegerToString(GetLastError()));
   }
}