2026-02-17 22:03:35 +01:00
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Market_Calendar_Pro.mq5 |
|
|
|
|
|
//| Fundamental Risk Mapper for QuantScan |
|
|
|
|
|
//| Copyright 2026, xxxxxxxx |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
#property copyright "Copyright 2026, xxxxxxxx"
|
2026-04-26 21:36:11 +02:00
|
|
|
#property version "2.20" // Added explicit DATE column to CSV output
|
2026-02-17 22:03:35 +01:00
|
|
|
#property description "Exports Daily Economic Events to CSV."
|
|
|
|
|
#property script_show_inputs
|
|
|
|
|
|
|
|
|
|
//--- Input Parameters
|
|
|
|
|
input group "Calendar Settings"
|
2026-04-26 21:36:11 +02:00
|
|
|
input datetime InpDateFrom = 0; // Start Date (0 = Today)
|
2026-02-17 22:03:35 +01:00
|
|
|
input bool InpFilterHighOnly = false; // Show only High Impact?
|
|
|
|
|
input bool InpIncludeMedium = true; // Include Medium Impact?
|
|
|
|
|
|
|
|
|
|
//--- Selected Currencies
|
2026-02-17 22:05:23 +01:00
|
|
|
string g_currencies[] = {"USD", "EUR", "GBP", "JPY", "CHF", "AUD"};
|
2026-02-17 22:03:35 +01:00
|
|
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//| Script Start |
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
void OnStart()
|
|
|
|
|
{
|
|
|
|
|
// 1. Define Time Range
|
|
|
|
|
datetime time_start = (InpDateFrom == 0) ? iTime(NULL, PERIOD_D1, 0) : InpDateFrom;
|
2026-04-26 21:36:11 +02:00
|
|
|
datetime time_end = time_start + 86400; // 24 hours later
|
2026-02-17 22:03:35 +01:00
|
|
|
|
2026-04-26 21:36:11 +02:00
|
|
|
// 2. Output File
|
2026-02-17 22:03:35 +01:00
|
|
|
string date_str = TimeToString(time_start, TIME_DATE); // "2026.02.17"
|
2026-04-26 21:36:11 +02:00
|
|
|
StringReplace(date_str, ".", ""); // "20260217"
|
2026-02-17 22:03:35 +01:00
|
|
|
string filename = "MarketCalendar_" + date_str + ".csv";
|
|
|
|
|
|
|
|
|
|
int file_handle = FileOpen(filename, FILE_CSV|FILE_WRITE|FILE_ANSI, ";");
|
|
|
|
|
if(file_handle == INVALID_HANDLE)
|
|
|
|
|
{
|
|
|
|
|
Print("Error opening CSV.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-26 21:36:11 +02:00
|
|
|
// Write Header (Added DATE column)
|
|
|
|
|
FileWrite(file_handle, "DATE", "TIME", "COUNTRY", "CURRENCY", "IMPORTANCE", "EVENT", "PREVIOUS", "FORECAST", "ACTUAL");
|
2026-02-17 22:03:35 +01:00
|
|
|
|
|
|
|
|
// 3. Fetch Events
|
|
|
|
|
MqlCalendarValue values[];
|
|
|
|
|
|
|
|
|
|
if(CalendarValueHistory(values, time_start, time_end))
|
|
|
|
|
{
|
|
|
|
|
int total = ArraySize(values);
|
|
|
|
|
PrintFormat("Found %d events. Processing...", total);
|
|
|
|
|
|
2026-04-26 21:36:11 +02:00
|
|
|
for(int i = 0; i < total; i++)
|
2026-02-17 22:03:35 +01:00
|
|
|
{
|
|
|
|
|
ulong event_id = values[i].event_id;
|
|
|
|
|
MqlCalendarEvent event;
|
|
|
|
|
MqlCalendarCountry country;
|
|
|
|
|
|
|
|
|
|
if(!CalendarEventById(event_id, event))
|
|
|
|
|
continue;
|
|
|
|
|
if(!CalendarCountryById(event.country_id, country))
|
|
|
|
|
continue;
|
|
|
|
|
|
2026-04-26 21:36:11 +02:00
|
|
|
// Checker for Target Currencies
|
2026-02-17 22:03:35 +01:00
|
|
|
bool currency_match = false;
|
2026-04-26 21:36:11 +02:00
|
|
|
for(int c = 0; c < ArraySize(g_currencies); c++)
|
2026-02-17 22:03:35 +01:00
|
|
|
{
|
|
|
|
|
if(country.currency == g_currencies[c])
|
|
|
|
|
{
|
|
|
|
|
currency_match = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!currency_match)
|
|
|
|
|
continue;
|
|
|
|
|
|
2026-04-26 21:36:11 +02:00
|
|
|
// Impact Filter Logic
|
2026-02-17 22:03:35 +01:00
|
|
|
bool is_high = (event.importance == CALENDAR_IMPORTANCE_HIGH);
|
|
|
|
|
bool is_med = (event.importance == CALENDAR_IMPORTANCE_MODERATE);
|
|
|
|
|
|
|
|
|
|
if(InpFilterHighOnly && !is_high)
|
|
|
|
|
continue;
|
|
|
|
|
if(!InpFilterHighOnly && !InpIncludeMedium && !is_high)
|
|
|
|
|
continue;
|
|
|
|
|
if(!is_high && !is_med)
|
|
|
|
|
continue;
|
|
|
|
|
|
2026-04-26 21:36:11 +02:00
|
|
|
// Format Date and Time explicitly
|
|
|
|
|
string date_val_str = TimeToString(values[i].time, TIME_DATE); // e.g. "2026.04.26"
|
|
|
|
|
string time_val_str = TimeToString(values[i].time, TIME_MINUTES); // e.g. "14:30"
|
|
|
|
|
|
2026-02-17 22:03:35 +01:00
|
|
|
string impact = (is_high) ? "HIGH" : "MEDIUM";
|
|
|
|
|
|
2026-04-26 21:36:11 +02:00
|
|
|
// Format Values
|
2026-02-17 22:03:35 +01:00
|
|
|
string s_prev = values[i].HasPreviousValue() ? DoubleToString(values[i].GetPreviousValue(), 2) : "-";
|
|
|
|
|
string s_fore = values[i].HasForecastValue() ? DoubleToString(values[i].GetForecastValue(), 2) : "-";
|
|
|
|
|
string s_act = values[i].HasActualValue() ? DoubleToString(values[i].GetActualValue(), 2) : "-";
|
|
|
|
|
|
2026-04-26 21:36:11 +02:00
|
|
|
// Clean Event Name (Prevent CSV delimiter issues)
|
2026-02-17 22:03:35 +01:00
|
|
|
string ev_name = event.name;
|
|
|
|
|
StringReplace(ev_name, ";", " ");
|
|
|
|
|
|
2026-04-26 21:36:11 +02:00
|
|
|
// Write Row
|
2026-02-17 22:03:35 +01:00
|
|
|
FileWrite(file_handle,
|
2026-04-26 21:36:11 +02:00
|
|
|
date_val_str,
|
|
|
|
|
time_val_str,
|
2026-02-17 22:03:35 +01:00
|
|
|
country.code, // e.g. "DE", "EU", "US"
|
|
|
|
|
country.currency, // e.g. "EUR", "USD"
|
|
|
|
|
impact,
|
|
|
|
|
ev_name,
|
2026-04-26 21:36:11 +02:00
|
|
|
s_prev,
|
|
|
|
|
s_fore,
|
|
|
|
|
s_act
|
2026-02-17 22:03:35 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-26 21:36:11 +02:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Print("No events found or failed to retrieve history.");
|
|
|
|
|
}
|
2026-02-17 22:03:35 +01:00
|
|
|
|
|
|
|
|
FileClose(file_handle);
|
|
|
|
|
Print("Done. File: ", filename);
|
|
|
|
|
}
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
|
|
|
//+------------------------------------------------------------------+
|