2026-09-28 13:31:44 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| TelegramNews.mq5 |
|
2026-09-28 16:56:13 -05:00 | | | //| Copyright 2026, Trade Systems Nique. |
|
| | | //| https://www.mql5.com/es/users/nique_372 |
|
2026-09-28 13:31:44 -05:00 | | | //+------------------------------------------------------------------+
|
2026-09-28 15:36:08 -05:00 | | | #property copyright "Copyright 2026, Trade Systems Nique"
|
2026-09-28 16:56:13 -05:00 | | | #property link "https://www.mql5.com/es/users/nique_372"
|
2026-09-28 13:31:44 -05:00 | | | #property version "1.00"
|
| | | #property strict
|
2026-09-28 16:56:13 -05:00 | | | #property description "Economic calendar watcher that sends a heads-up to Telegram before a scheduled news event hits."
|
| | | #property icon "logo.ico"
|
2026-09-28 13:31:44 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-28 16:56:13 -05:00 | | | //| Pre-Defines |
|
2026-09-28 13:31:44 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //#define TELEGRAMBYLEO_TLGAPI_DEBUG_SEND
|
| | | #define MARKETMT5_VER
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-28 16:56:13 -05:00 | | | //| Include |
|
2026-09-28 13:31:44 -05:00 | | | //+------------------------------------------------------------------+
|
| | | #include "Secrets.mqh"
|
| | | #include "Src\\Main.mqh"
|
| | | #include <TSN\\MQLArticles\\Utils\\FA\\BarControler.mqh>
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| Inputs |
|
| | | //+------------------------------------------------------------------+
|
| | | sinput group "-------| Configuration |-------"
|
| | | #ifdef MARKETMT5_VER
|
2026-09-28 16:56:13 -05:00 | | | const string InpTbpLicense = "";
|
2026-09-28 13:31:44 -05:00 | | | #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 "
|
2026-09-28 16:56:13 -05:00 | | | input datetime fecha_desde_incio_noticias = D'2005.01.01'; // Start date for calendar data collection
|
2026-09-28 15:36:08 -05:00 | | | 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)
|
2026-09-28 13:31:44 -05:00 | | |
|
2026-09-28 16:56:13 -05:00 | | | sinput group "--| Filters "
|
| | | input ENUM_CALENDARFILTER_TYPE InpNewsFilter = CALENDARFILTER_NONE; // Select the news filter type:
|
| | | sinput group "- Filter by list of country codes -"
|
2026-09-28 17:04:59 -05:00 | | | input string InpNewsFilterListCountries = ""; // List the countries to be incluyed in tracking here (ISO 3166-1 alpha-2) separated by commas
|
2026-09-28 16:56:13 -05:00 | | |
|
2026-09-28 13:31:44 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| 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;
|
| | | }
|
| | |
|
2026-09-28 16:56:13 -05:00 | | | // 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
|
2026-09-28 13:31:44 -05:00 | | | calendar.AddAllCountries(importancia_eventos_a_filtrar);
|
| | |
|
2026-09-28 16:56:13 -05:00 | | | //--- seteo del calendario
|
2026-09-28 13:31:44 -05:00 | | | calendar.SetNoticiasChecker(seg_antes_despues, 10);
|
| | | calendar.SetObtenerValoresActuales(false);
|
| | | calendar.SetCalendar(desde, hasta);
|
| | |
|
2026-09-28 16:56:13 -05:00 | | | //--- hook para recibnir eventos
|
2026-09-28 13:31:44 -05:00 | | | calendar.AddHook(&telegram);
|
| | |
|
| | | //---
|
| | | // news
|
| | | if(!telegram.Init(_Symbol))
|
| | | {
|
2026-09-28 16:56:13 -05:00 | | | FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT, StringFormat("Error in get data for symbol = %s", _Symbol));
|
2026-09-28 13:31:44 -05:00 | | | 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);
|
| | | }
|
| | | }
|
| | | //+------------------------------------------------------------------+
|
| | | //+------------------------------------------------------------------+
|