//+------------------------------------------------------------------+ //| TelegramNews.mq5 | //| Copyright 2026, Trade Systems Nique. | //| https://www.mql5.com/es/users/nique_372 | //+------------------------------------------------------------------+ #property copyright "Copyright 2026, Trade Systems Nique" #property link "https://www.mql5.com/es/users/nique_372" #property version "1.00" #property strict #property description "Economic calendar watcher that sends a heads-up to Telegram before a scheduled news event hits." #property icon "logo.ico" //+------------------------------------------------------------------+ //| Pre-Defines | //+------------------------------------------------------------------+ //#define TELEGRAMBYLEO_TLGAPI_DEBUG_SEND #define MARKETMT5_VER //+------------------------------------------------------------------+ //| Include | //+------------------------------------------------------------------+ #include "Secrets.mqh" #include "Src\\Main.mqh" #include //+------------------------------------------------------------------+ //| Inputs | //+------------------------------------------------------------------+ sinput group "-------| Configuration |-------" #ifdef MARKETMT5_VER const string InpTbpLicense = ""; #else // MARKETMT5_VER sinput group "--| News TBP License " input string InpTbpLicense = THE_BOT_PLACE_USER_ID; // Put here your user-id TBP #endif // MARKETMT5_VER sinput group "--| Telegram " input string InpBotToken = ""; // Telegram bot token input long InpChatId = 0; // Telegram chat id sinput group "--| News " input datetime fecha_desde_incio_noticias = D'2005.01.01'; // Start date for calendar data collection input uint16_t seg_antes_despues = 15; // Seconds before the alert event input string importancia_eventos_a_filtrar = "High|Medium|Low"; // Importance of events to consider (High | Low | Medium) sinput group "--| Filters " input ENUM_CALENDARFILTER_TYPE InpNewsFilter = CALENDARFILTER_NONE; // Select the news filter type: sinput group "- Filter by list of country codes -" input string InpNewsFilterListCountries = ""; // List the countries to be incluyed in tracking here (ISO 3166-1 alpha-2) separated by commas //+------------------------------------------------------------------+ //| Global variables | //+------------------------------------------------------------------+ TSN::CBarControlerFastMinors controler_d1(PERIOD_D1); CTelegramsNews telegram; TSN::ICalendarByLeo* calendar = NULL; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- Caledario datetime desde = fecha_desde_incio_noticias; datetime hasta = iTime(_Symbol, PERIOD_D1, 0); //--- #ifdef TSN_FASTNL_FUNC_CTS TSN_FASTNL_FUNC_CTS(InpTbpLicense); #else CiNewsLeo_CalendarInit(InpTbpLicense); #endif // Calendario calendar = CiNewsLeo_CreateEconomicCalendar(); if(calendar == NULL) { FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT, "Error in create economic calendar (check your license)"); return INIT_PARAMETERS_INCORRECT; } // configuramos el filtro if(InpNewsFilter == CALENDARFILTER_TYPE_BY_CURRENT_SYMBOL) { calendar.FilterBySymbol(_Symbol); } else if(InpNewsFilter == CALENDARFILTER_TYPE_BY_COUNTRIES) { ulong countries[]; TSN::NewsByLeo_CountryCodeStrToIdList(InpNewsFilterListCountries, ',', countries); if(!calendar.FilterByCountryList(countries)) { FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT, "The list of countries must contain at least one entry, and entries must be separated by commas."); return INIT_PARAMETERS_INCORRECT; } } //--- aƱadimos todos los eventos calendar.AddAllCountries(importancia_eventos_a_filtrar); //--- seteo del calendario calendar.SetNoticiasChecker(seg_antes_despues, 10); calendar.SetObtenerValoresActuales(false); calendar.SetCalendar(desde, hasta); //--- hook para recibnir eventos calendar.AddHook(&telegram); //--- // news if(!telegram.Init(_Symbol)) { FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT, StringFormat("Error in get data for symbol = %s", _Symbol)); return INIT_PARAMETERS_INCORRECT; } // tlg TSN::CTelegramAPI* tlg_api = telegram.GetBotPtr(); tlg_api.ChatId(InpChatId); //Pon el chat id donde se enviaran los mensajes tlg_api.Token(InpBotToken); // Pon el token de tu bot de telegram //--- calendar.First(TimeCurrent()); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { if(calendar != NULL) delete calendar; } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- const datetime time_curr = TimeCurrent(); //--- if(controler_d1.IsNewBar(time_curr)) { calendar.OnNewDay(time_curr); } //--- calendar.OnTickEvent(time_curr); //--- Buscamos si hay noticias ya establecidas para loguear o continuar con las siguientes if(calendar.NewsIsComming()) //Verificar si una funcion se acerca.. { calendar.GetEvents(time_curr); calendar.OnEndNews(time_curr); } } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+