forked from nique_372/TlgNewsInformer
//+------------------------------------------------------------------+
| |
//| 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.01"
| |
#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 <TSN\\MQLArticles\\Utils\\FA\\BarControler.mqh>
| |
#include <TSN\\Std\\Basics\\Try.mqh>
| |
| |
//+------------------------------------------------------------------+
| |
//| 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
| |
input int InpTimeout = 5000; // Telegram (WebRequest) Timeout ms
| |
| |
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_D1 controler_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);
| |
| |
//---
| |
string _what = NULL;
| |
TSNSTD_TRY_INI
| |
{
| |
| |
//---
| |
#ifdef TSN_FASTNL_FUNC_CTS
| |
TSN_FASTNL_FUNC_CTS(InpTbpLicense);
| |
#else
| |
CiNewsLeo_CalendarInit(InpTbpLicense);
| |
#endif
| |
| |
// 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.")
| |
| |
// configuramos el filtro
| |
if(InpNewsFilter == CALENDARFILTER_TYPE_BY_CURRENT_SYMBOL)
| |
{
| |
TSNSTD_TRY_EF(calendar.FilterBySymbol(_Symbol), true, CiNewsLeo_FormatTraceFirst(_what));
| |
}
| |
else
| |
if(InpNewsFilter == CALENDARFILTER_TYPE_BY_COUNTRIES)
| |
{
| |
ulong countries[];
| |
TSN::NewsByLeo_CountryCodeStrToIdList(InpNewsFilterListCountries, ',', countries);
| |
TSNSTD_TRY_EF(calendar.FilterByCountryList(countries), true, CiNewsLeo_FormatTraceFirst(_what));
| |
}
| |
| |
//--- añadimos todos los eventos
| |
TSNSTD_TRY_EF(calendar.AddAllCountries(importancia_eventos_a_filtrar), true, CiNewsLeo_FormatTraceFirst(_what));
| |
| |
//--- seteo del calendario
| |
calendar.SetNoticiasChecker(seg_antes_despues, 10);
| |
calendar.SetObtenerValoresActuales(false);
| |
TSNSTD_TRY_EF(calendar.SetCalendar(desde, hasta), true, CiNewsLeo_FormatTraceFirst(_what));
| |
| |
//--- 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()));
| |
| |
// 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));
| |
| |
//---
| |
}
| |
TSNSTD_TRY_END;
| |
| |
//---
| |
if(_what != NULL)
| |
{
| |
FastLog(FUNCION_ACTUAL, FATAL_ERROR_TEXT, _what);
| |
return(INIT_FAILED);
| |
}
| |
| |
//---
| |
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);
| |
}
| |
}
| |
//+------------------------------------------------------------------+
| |
//+------------------------------------------------------------------+
|