Need help calendar

 

Hello guys,

I want to send calendar information via API but when I retrieve data as the below code, it returns a number without format, I want to receive the data which is shown on MetaTrader Calendar. Please help me. How can I do?

Thanks in advance.

void CalendarData()
{
   // Define the array to hold calendar values
   MqlCalendarValue values[]; 
   MqlCalendarCountry country;
   MqlCalendarEvent event;
   
   // Define the time range for calendar events
   datetime from_time = TimeCurrent();
   datetime to_time = TimeCurrent() + 1 * 86400; // Current time + 1 day

   // Retrieve calendar events
   int values_count = CalendarValueHistory(values, from_time, to_time);

   // Check if events are available
   if(values_count > 0)
   {
      Print("Number of events: ", values_count);

      for(int i = 0; i < values_count; i++)
      {
         int event_id = values[i].event_id; 
         
         // Scale values by dividing by 10^6 (to get the actual value)
         double act_value = values[i].actual_value / 1000000.0; 
         double fore_value = values[i].forecast_value / 1000000.0;
         double pre_value = values[i].prev_value / 1000000.0;
         datetime time = values[i].time;
         datetime period = values[i].period;
         
         string unit_str = ""; 
         string multiplier_str = "";
         string formatted_act_value, formatted_fore_value, formatted_pre_value;

         // Assuming event type determines the unit (for example, percentage or scaled value)
         // Assigning units based on conditions or event types
         if (event_id % 2 == 0)  // This is just an example condition, change it based on your logic
         {
            unit_str = "%"; // For events that use percentage
         }
         else
         {
            unit_str = ""; // No unit for other events (you can assign other logic here)
         }

         // Manually determine the multiplier based on custom logic
         double multiplier = 1.0; // Default multiplier

         if (event_id % 3 == 0)  // Custom condition for millions (just an example, change it to fit your needs)
         {
            multiplier = 1000000.0;
            multiplier_str = "M"; // Millions
         }
         else if (event_id % 5 == 0)  // Custom condition for thousands
         {
            multiplier = 1000.0;
            multiplier_str = "K"; // Thousands
         }
         else if (event_id % 7 == 0)  // Custom condition for billions
         {
            multiplier = 1000000000.0;
            multiplier_str = "B"; // Billions
         }

         // Adjust values with the manually defined multiplier
         act_value *= multiplier;
         fore_value *= multiplier;
         pre_value *= multiplier;

         // Format values with unit and multiplier (only append multiplier if it's not empty)
         formatted_act_value = StringFormat("%.2f%s", act_value, multiplier_str + unit_str);
         formatted_fore_value = StringFormat("%.2f%s", fore_value, multiplier_str + unit_str);
         formatted_pre_value = StringFormat("%.2f%s", pre_value, multiplier_str + unit_str);
         
         if (CalendarEventById(event_id,event))
         {
            int importance = event.importance;
            CalendarCountryById(event.country_id, country);
            string country_code = country.currency;
            string event_name = event.name;
            Print("Event: ", event_id, "\Event name: ", event_name, "\nTime: ", TimeToString(time, TIME_DATE|TIME_MINUTES), "\nCountry: ", country_code, 
         "\nImportance: ", importance);
         SendCalendartoAPI(country_code,TimeToString(time, TIME_DATE|TIME_MINUTES),event_name, importance,TimeToString(period, TIME_DATE|TIME_MINUTES),
                           formatted_act_value, formatted_fore_value, formatted_pre_value);
         }
         
      }
   }
   else
   {
      Print("No calendar events found.");
   }
}
 
hoang huyen:

Hello guys,

I want to send calendar information via API but when I retrieve data as the below code, it returns a number without format, I want to receive the data which is shown on MetaTrader Calendar. Please help me. How can I do?

Thanks in advance.


Take a look at this:

ENUM_CALENDAR_EVENT_UNIT

ENUM_CALENDAR_EVENT_MULTIPLIER

Which are given to you in:

https://www.mql5.com/en/docs/constants/structures/mqlcalendar#mqlcalendarevent