mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-07-27 20:47:44 +00:00
refactor: Added explicit DATE column to CSV output
This commit is contained in:
@@ -4,13 +4,13 @@
|
|||||||
//| Copyright 2026, xxxxxxxx |
|
//| Copyright 2026, xxxxxxxx |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2026, xxxxxxxx"
|
#property copyright "Copyright 2026, xxxxxxxx"
|
||||||
#property version "2.10" // Added Country Code + Fixed Filename
|
#property version "2.20" // Added explicit DATE column to CSV output
|
||||||
#property description "Exports Daily Economic Events to CSV."
|
#property description "Exports Daily Economic Events to CSV."
|
||||||
#property script_show_inputs
|
#property script_show_inputs
|
||||||
|
|
||||||
//--- Input Parameters
|
//--- Input Parameters
|
||||||
input group "Calendar Settings"
|
input group "Calendar Settings"
|
||||||
input datetime InpDateFrom = 0; // Start Date (0 = Today)
|
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?
|
||||||
|
|
||||||
@@ -24,11 +24,11 @@ void OnStart()
|
|||||||
{
|
{
|
||||||
// 1. Define Time Range
|
// 1. Define Time Range
|
||||||
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;
|
datetime time_end = time_start + 86400; // 24 hours later
|
||||||
|
|
||||||
// 2. Output File (Fixed Logic)
|
// 2. Output File
|
||||||
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";
|
||||||
|
|
||||||
int file_handle = FileOpen(filename, FILE_CSV|FILE_WRITE|FILE_ANSI, ";");
|
int file_handle = FileOpen(filename, FILE_CSV|FILE_WRITE|FILE_ANSI, ";");
|
||||||
@@ -38,8 +38,8 @@ void OnStart()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Header Updated
|
// Write Header (Added DATE column)
|
||||||
FileWrite(file_handle, "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
|
||||||
MqlCalendarValue values[];
|
MqlCalendarValue values[];
|
||||||
@@ -49,7 +49,7 @@ void OnStart()
|
|||||||
int total = ArraySize(values);
|
int total = ArraySize(values);
|
||||||
PrintFormat("Found %d events. Processing...", total);
|
PrintFormat("Found %d events. Processing...", total);
|
||||||
|
|
||||||
for(int i=0; i<total; i++)
|
for(int i = 0; i < total; i++)
|
||||||
{
|
{
|
||||||
ulong event_id = values[i].event_id;
|
ulong event_id = values[i].event_id;
|
||||||
MqlCalendarEvent event;
|
MqlCalendarEvent event;
|
||||||
@@ -60,9 +60,9 @@ void OnStart()
|
|||||||
if(!CalendarCountryById(event.country_id, country))
|
if(!CalendarCountryById(event.country_id, country))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Checker
|
// Checker for 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++)
|
||||||
{
|
{
|
||||||
if(country.currency == g_currencies[c])
|
if(country.currency == g_currencies[c])
|
||||||
{
|
{
|
||||||
@@ -73,6 +73,7 @@ void OnStart()
|
|||||||
if(!currency_match)
|
if(!currency_match)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Impact Filter Logic
|
||||||
bool is_high = (event.importance == CALENDAR_IMPORTANCE_HIGH);
|
bool is_high = (event.importance == CALENDAR_IMPORTANCE_HIGH);
|
||||||
bool is_med = (event.importance == CALENDAR_IMPORTANCE_MODERATE);
|
bool is_med = (event.importance == CALENDAR_IMPORTANCE_MODERATE);
|
||||||
|
|
||||||
@@ -83,27 +84,39 @@ void OnStart()
|
|||||||
if(!is_high && !is_med)
|
if(!is_high && !is_med)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
string time_str = TimeToString(values[i].time, TIME_MINUTES);
|
// 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"
|
||||||
|
|
||||||
string impact = (is_high) ? "HIGH" : "MEDIUM";
|
string impact = (is_high) ? "HIGH" : "MEDIUM";
|
||||||
|
|
||||||
|
// Format 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)
|
||||||
string ev_name = event.name;
|
string ev_name = event.name;
|
||||||
StringReplace(ev_name, ";", " ");
|
StringReplace(ev_name, ";", " ");
|
||||||
|
|
||||||
// Write Row with Country Code
|
// Write Row
|
||||||
FileWrite(file_handle,
|
FileWrite(file_handle,
|
||||||
time_str,
|
date_val_str,
|
||||||
|
time_val_str,
|
||||||
country.code, // e.g. "DE", "EU", "US"
|
country.code, // e.g. "DE", "EU", "US"
|
||||||
country.currency, // e.g. "EUR", "USD"
|
country.currency, // e.g. "EUR", "USD"
|
||||||
impact,
|
impact,
|
||||||
ev_name,
|
ev_name,
|
||||||
s_prev, s_fore, s_act
|
s_prev,
|
||||||
|
s_fore,
|
||||||
|
s_act
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Print("No events found or failed to retrieve history.");
|
||||||
|
}
|
||||||
|
|
||||||
FileClose(file_handle);
|
FileClose(file_handle);
|
||||||
Print("Done. File: ", filename);
|
Print("Done. File: ", filename);
|
||||||
|
|||||||
Reference in New Issue
Block a user