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-11-03 13:37:42 -05:00
# property version " 1.01 "
2026-09-28 13:31:44 -05: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>
2026-11-03 13:34:00 -05:00
# include <TSN\\Std\\Basics\\Try.mqh>
2026-09-28 13:31:44 -05:00
//+------------------------------------------------------------------+
//| 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
2026-11-03 13:34:00 -05:00
input int InpTimeout = 5000 ; // Telegram (WebRequest) Timeout ms
2026-09-28 13:31:44 -05:00
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 |
//+------------------------------------------------------------------+
2026-11-02 17:26:28 -05:00
TSN : : CBarControlerFastMinors_D1 controler_d1 ;
2026-09-28 13:31:44 -05:00
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 ) ;
//---
2026-11-03 13:34:00 -05:00
string _what = NULL ;
TSNSTD_TRY_INI
{
//---
2026-09-28 13:31:44 -05:00
# ifdef TSN_FASTNL_FUNC_CTS
2026-11-03 13:34:00 -05:00
TSN_FASTNL_FUNC_CTS ( InpTbpLicense ) ;
2026-09-28 13:31:44 -05:00
# else
2026-11-03 13:34:00 -05:00
CiNewsLeo_CalendarInit ( InpTbpLicense ) ;
2026-09-28 13:31:44 -05:00
# endif
2026-11-03 13:34:00 -05:00
// Calendario
calendar = CiNewsLeo_CreateEconomicCalendar ( ) ;
TSNSTD_TRY_EF ( CheckPointer ( calendar ) , POINTER_DYNAMIC , _what = " Failed to create the calendar using CiNewsLeo Create Economic Calendar; please check your license. " )
2026-09-28 13:31:44 -05:00
2026-11-03 13:34:00 -05:00
// configuramos el filtro
if ( InpNewsFilter = = CALENDARFILTER_TYPE_BY_CURRENT_SYMBOL )
2026-09-28 16:56:13 -05:00
{
2026-11-05 12:16:35 -05:00
TSNSTD_TRY_EF ( calendar . FilterBySymbol ( _Symbol ) , true , CiNewsLeo_FormatTraceFirst ( _what ) ) ;
2026-11-03 13:34:00 -05:00
}
else
if ( InpNewsFilter = = CALENDARFILTER_TYPE_BY_COUNTRIES )
2026-09-28 16:56:13 -05:00
{
2026-11-03 13:34:00 -05:00
ulong countries [ ] ;
TSN : : NewsByLeo_CountryCodeStrToIdList ( InpNewsFilterListCountries , ' , ' , countries ) ;
2026-11-05 12:16:35 -05:00
TSNSTD_TRY_EF ( calendar . FilterByCountryList ( countries ) , true , CiNewsLeo_FormatTraceFirst ( _what ) ) ;
2026-09-28 16:56:13 -05:00
}
2026-11-03 13:34:00 -05:00
//--- añadimos todos los eventos
2026-11-05 12:16:35 -05:00
TSNSTD_TRY_EF ( calendar . AddAllCountries ( importancia_eventos_a_filtrar ) , true , CiNewsLeo_FormatTraceFirst ( _what ) ) ;
2026-09-28 13:31:44 -05:00
2026-11-03 13:34:00 -05:00
//--- seteo del calendario
calendar . SetNoticiasChecker ( seg_antes_despues , 10 ) ;
calendar . SetObtenerValoresActuales ( false ) ;
2026-11-05 12:16:35 -05:00
TSNSTD_TRY_EF ( calendar . SetCalendar ( desde , hasta ) , true , CiNewsLeo_FormatTraceFirst ( _what ) ) ;
2026-09-28 13:31:44 -05:00
2026-11-03 13:34:00 -05:00
//--- hook para recibnir eventos
calendar . AddHook ( & telegram ) ;
//---
// news
TSNSTD_TRY_EF ( telegram .Init ( _Symbol ) , true , _what = StringFormat ( " Error in get data for symbol = %s, last mql5 err = %d " , _Symbol , : : GetLastError ( ) ) ) ;
2026-11-05 12:16:35 -05:00
// tlg config
TSN : : CTelegramAPI * tlg_api = telegram . GetBotPtr ( ) ;
tlg_api . ChatId ( InpChatId ) ;
tlg_api . Token ( InpBotToken ) ;
tlg_api . Timeout ( InpTimeout ) ;
//---
TSNSTD_TRY_EF ( calendar . First ( TimeCurrent ( ) ) , true , CiNewsLeo_FormatTraceFirst ( _what ) ) ;
//---
2026-11-03 13:34:00 -05:00
}
TSNSTD_TRY_END ;
2026-09-28 13:31:44 -05:00
//---
2026-11-03 13:34:00 -05:00
if ( _what ! = NULL )
2026-09-28 13:31:44 -05:00
{
2026-11-03 13:34:00 -05:00
FastLog ( FUNCION_ACTUAL , FATAL_ERROR_TEXT , _what ) ;
return ( INIT_FAILED ) ;
2026-09-28 13:31:44 -05:00
}
//---
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 ) ;
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+