125 lines
No EOL
6 KiB
MQL5
125 lines
No EOL
6 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| MQL5 News Calendar EA PART 12.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 with SQLite Database"
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| 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 - Data Download Settings |
|
|
//+------------------------------------------------------------------+
|
|
input group "=== DATA DOWNLOAD SETTINGS ==="
|
|
input bool inp_DownloadDataInLive = false; // Download NEWS data for offline testing?
|
|
input datetime inp_DownloadStartDate = D'2026.01.01'; // Download range: START date
|
|
input datetime inp_DownloadEndDate = D'2026.05.12'; // Download range: END date
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Inputs - Backtest Settings |
|
|
//+------------------------------------------------------------------+
|
|
input group "=== BACKTEST SETTINGS ==="
|
|
input datetime StartDate = D'2026.01.01'; // Backtest window: START date
|
|
input datetime EndDate = D'2026.05.12'; // Backtest 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 definitions and state
|
|
#include "News Core.mqh"
|
|
//--- Include SQLite database layer for persistent calendar storage
|
|
#include "News Database.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();
|
|
}
|
|
//+------------------------------------------------------------------+ |