refactor: Advanced Sector Filtering & Holiday Bypass

This commit is contained in:
Toh4iem9
2026-05-03 21:38:57 +02:00
parent 30d47c5086
commit 6679a0a816
+60 -24
View File
@@ -4,7 +4,7 @@
//| Copyright 2026, xxxxxxxx | //| Copyright 2026, xxxxxxxx |
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
#property copyright "Copyright 2026, xxxxxxxx" #property copyright "Copyright 2026, xxxxxxxx"
#property version "2.20" // Added explicit DATE column to CSV output #property version "3.00" // Advanced Sector Filtering & Holiday Bypass
#property description "Exports Daily Economic Events to CSV." #property description "Exports Daily Economic Events to CSV."
#property script_show_inputs #property script_show_inputs
@@ -14,7 +14,7 @@ input datetime InpDateFrom = 0; // Start Date (0 = Today)
input bool InpFilterHighOnly = false; // Show only High Impact? input bool InpFilterHighOnly = false; // Show only High Impact?
input bool InpIncludeMedium = true; // Include Medium Impact? input bool InpIncludeMedium = true; // Include Medium Impact?
//--- Selected Currencies //--- Selected Currencies (Core Portfolio Exposure)
string g_currencies[] = {"USD", "EUR", "GBP", "JPY", "CHF", "AUD"}; string g_currencies[] = {"USD", "EUR", "GBP", "JPY", "CHF", "AUD"};
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
@@ -26,7 +26,7 @@ void OnStart()
datetime time_start = (InpDateFrom == 0) ? iTime(NULL, PERIOD_D1, 0) : InpDateFrom; datetime time_start = (InpDateFrom == 0) ? iTime(NULL, PERIOD_D1, 0) : InpDateFrom;
datetime time_end = time_start + 86400; // 24 hours later datetime time_end = time_start + 86400; // 24 hours later
// 2. Output File // 2. Output File Setup
string date_str = TimeToString(time_start, TIME_DATE); // "2026.02.17" string date_str = TimeToString(time_start, TIME_DATE); // "2026.02.17"
StringReplace(date_str, ".", ""); // "20260217" StringReplace(date_str, ".", ""); // "20260217"
string filename = "MarketCalendar_" + date_str + ".csv"; string filename = "MarketCalendar_" + date_str + ".csv";
@@ -34,11 +34,11 @@ void OnStart()
int file_handle = FileOpen(filename, FILE_CSV|FILE_WRITE|FILE_ANSI, ";"); int file_handle = FileOpen(filename, FILE_CSV|FILE_WRITE|FILE_ANSI, ";");
if(file_handle == INVALID_HANDLE) if(file_handle == INVALID_HANDLE)
{ {
Print("Error opening CSV."); Print("Error opening CSV for writing.");
return; return;
} }
// Write Header (Added DATE column) // Write Header (Explicit DATE column included)
FileWrite(file_handle, "DATE", "TIME", "COUNTRY", "CURRENCY", "IMPORTANCE", "EVENT", "PREVIOUS", "FORECAST", "ACTUAL"); FileWrite(file_handle, "DATE", "TIME", "COUNTRY", "CURRENCY", "IMPORTANCE", "EVENT", "PREVIOUS", "FORECAST", "ACTUAL");
// 3. Fetch Events // 3. Fetch Events
@@ -47,7 +47,8 @@ void OnStart()
if(CalendarValueHistory(values, time_start, time_end)) if(CalendarValueHistory(values, time_start, time_end))
{ {
int total = ArraySize(values); int total = ArraySize(values);
PrintFormat("Found %d events. Processing...", total); PrintFormat("Found %d total events. Applying Portfolio Filters...", total);
int written_rows = 0;
for(int i = 0; i < total; i++) for(int i = 0; i < total; i++)
{ {
@@ -60,7 +61,7 @@ void OnStart()
if(!CalendarCountryById(event.country_id, country)) if(!CalendarCountryById(event.country_id, country))
continue; continue;
// Checker for Target Currencies // --- FILTER 1: Target Currencies ---
bool currency_match = false; bool currency_match = false;
for(int c = 0; c < ArraySize(g_currencies); c++) for(int c = 0; c < ArraySize(g_currencies); c++)
{ {
@@ -73,29 +74,60 @@ void OnStart()
if(!currency_match) if(!currency_match)
continue; continue;
// Impact Filter Logic // --- FILTER 2: Target Macro Sectors ---
bool is_high = (event.importance == CALENDAR_IMPORTANCE_HIGH); bool is_core_macro = false;
bool is_med = (event.importance == CALENDAR_IMPORTANCE_MODERATE); switch(event.sector)
{
case CALENDAR_SECTOR_BUSINESS:
case CALENDAR_SECTOR_CONSUMER:
case CALENDAR_SECTOR_GDP:
case CALENDAR_SECTOR_HOLIDAYS:
case CALENDAR_SECTOR_JOBS:
case CALENDAR_SECTOR_MARKET:
case CALENDAR_SECTOR_MONEY:
case CALENDAR_SECTOR_PRICES:
is_core_macro = true;
break;
}
if(InpFilterHighOnly && !is_high) // Drop irrelevant noise (e.g. Housing, Retail specific, Taxes, etc.)
continue; if(!is_core_macro)
if(!InpFilterHighOnly && !InpIncludeMedium && !is_high)
continue;
if(!is_high && !is_med)
continue; continue;
// Format Date and Time explicitly // --- FILTER 3: Importance (with Holiday Bypass) ---
string date_val_str = TimeToString(values[i].time, TIME_DATE); // e.g. "2026.04.26" string impact = "LOW/NONE";
string time_val_str = TimeToString(values[i].time, TIME_MINUTES); // e.g. "14:30"
string impact = (is_high) ? "HIGH" : "MEDIUM"; // Holidays are often marked as LOW/NONE importance in MT5,
// but we MUST pass them to the LLM.
if(event.sector == CALENDAR_SECTOR_HOLIDAYS)
{
impact = "HOLIDAY";
}
else
{
bool is_high = (event.importance == CALENDAR_IMPORTANCE_HIGH);
bool is_med = (event.importance == CALENDAR_IMPORTANCE_MODERATE);
// Format Values if(InpFilterHighOnly && !is_high)
continue;
if(!InpFilterHighOnly && !InpIncludeMedium && !is_high)
continue;
if(!is_high && !is_med)
continue; // Drop standard Low/None events
impact = (is_high) ? "HIGH" : "MEDIUM";
}
// Format Date and Time
string date_val_str = TimeToString(values[i].time, TIME_DATE); // "2026.04.26"
string time_val_str = TimeToString(values[i].time, TIME_MINUTES); // "14:30"
// Format Statistical Values
string s_prev = values[i].HasPreviousValue() ? DoubleToString(values[i].GetPreviousValue(), 2) : "-"; string s_prev = values[i].HasPreviousValue() ? DoubleToString(values[i].GetPreviousValue(), 2) : "-";
string s_fore = values[i].HasForecastValue() ? DoubleToString(values[i].GetForecastValue(), 2) : "-"; string s_fore = values[i].HasForecastValue() ? DoubleToString(values[i].GetForecastValue(), 2) : "-";
string s_act = values[i].HasActualValue() ? DoubleToString(values[i].GetActualValue(), 2) : "-"; string s_act = values[i].HasActualValue() ? DoubleToString(values[i].GetActualValue(), 2) : "-";
// Clean Event Name (Prevent CSV delimiter issues) // Clean Event Name (Prevent CSV delimiter breakage)
string ev_name = event.name; string ev_name = event.name;
StringReplace(ev_name, ";", " "); StringReplace(ev_name, ";", " ");
@@ -103,15 +135,19 @@ void OnStart()
FileWrite(file_handle, FileWrite(file_handle,
date_val_str, date_val_str,
time_val_str, time_val_str,
country.code, // e.g. "DE", "EU", "US" country.code,
country.currency, // e.g. "EUR", "USD" country.currency,
impact, impact,
ev_name, ev_name,
s_prev, s_prev,
s_fore, s_fore,
s_act s_act
); );
written_rows++;
} }
PrintFormat("Processing complete. Exported %d high-relevance portfolio events.", written_rows);
} }
else else
{ {
@@ -119,7 +155,7 @@ void OnStart()
} }
FileClose(file_handle); FileClose(file_handle);
Print("Done. File: ", filename); Print("Done. File saved: ", filename);
} }
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+
//+------------------------------------------------------------------+ //+------------------------------------------------------------------+