Article-22597-MQL5-Economic.../MQL5 News Calendar EA PART 11.mq5

121 lines
5.7 KiB
MQL5
Raw Permalink Normal View History

//+------------------------------------------------------------------+
//| MQL5 News Calendar EA PART 11.mq5 |
//| Copyright 2026, Allan Munene Mutiiria. |
//| https://t.me/Forex_Algo_Trader |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Allan Munene Mutiiria."
#property link "https://t.me/Forex_Algo_Trader"
#property version "1.00"
#property strict
#property description "MQL5 Economic News Calendar - Canvas-based Dashboard"
//+------------------------------------------------------------------+
//| Embedded Resources |
//+------------------------------------------------------------------+
//--- Embed CSV resource for strategy tester mode
#resource "\\Files\\Database\\EconomicCalendar.csv" as string EconomicCalendarData
//+------------------------------------------------------------------+
//| Inputs - General Calendar Settings |
//+------------------------------------------------------------------+
input group "=== GENERAL CALENDAR SETTINGS ==="
input ENUM_TIMEFRAMES start_time = PERIOD_H12; // Past time window for live mode
input ENUM_TIMEFRAMES end_time = PERIOD_H12; // Future time window for live mode
input ENUM_TIMEFRAMES range_time = PERIOD_H8; // Time filter range from now
input bool updateServerTime = true; // Update server clock on header
input bool debugLogging = false; // Print debug info to journal
//+------------------------------------------------------------------+
//| Inputs - Strategy Tester CSV Settings |
//+------------------------------------------------------------------+
input group "=== STRATEGY TESTER CSV SETTINGS ==="
input datetime StartDate = D'2026.01.01'; // Tester window start date
input datetime EndDate = D'2026.05.12'; // Tester window end date
//+------------------------------------------------------------------+
//| Inputs - Auto-Trading Settings |
//+------------------------------------------------------------------+
input group "=== AUTO-TRADING SETTINGS ==="
//+------------------------------------------------------------------+
//| Trade mode enumeration |
//+------------------------------------------------------------------+
enum ENewsTradeMode
{
NEWS_TRADE_BEFORE, // Trade before news event
NEWS_TRADE_AFTER, // Trade after news event
NEWS_NO_TRADE, // Do not trade on news
NEWS_PAUSE_TRADING // Pause trading around news
};
input ENewsTradeMode tradeMode = NEWS_TRADE_BEFORE; // Trade mode
input int tradeOffsetHours = 0; // Trade offset hours
input int tradeOffsetMinutes = 5; // Trade offset minutes
input int tradeOffsetSeconds = 0; // Trade offset seconds
input double tradeLotSize = 0.01; // Trade lot size
//+------------------------------------------------------------------+
//| Module Includes |
//+------------------------------------------------------------------+
//--- Define sentinel to prevent modules from emitting their own externs
#define NEWS_COMPILED_FROM_MAIN
//--- Include core data and calendar loading logic
#include "News Core.mqh"
//--- Include trade signal and logic handlers
#include "News Logic.mqh"
//--- Include canvas rendering and dashboard drawing
#include "News Render.mqh"
//--- Include mouse, click, and chart interaction handlers
#include "News Interact.mqh"
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- Initialize all news modules and abort if setup fails
if(!News_Init()) return INIT_FAILED;
//--- Start half-second timer for countdown and toast refresh
EventSetMillisecondTimer(500);
//---
return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- Kill the periodic timer
EventKillTimer();
//--- Clean up all news module resources
News_Deinit();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- Delegate tick handling to the news logic module
News_OnTick();
}
//+------------------------------------------------------------------+
//| Expert chart event function |
//+------------------------------------------------------------------+
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
//--- Delegate mouse, wheel, click, and drag events to interact module
News_OnChartEvent(id, lparam, dparam, sparam);
}
//+------------------------------------------------------------------+
//| Expert timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
//--- Trigger countdown updates and expire stale toast notifications
News_OnTimer();
}
//+------------------------------------------------------------------+