forked from nique_372/TlgNewsInformer
//+------------------------------------------------------------------+
| |
//| NewsTelegram.mqh |
| |
//| Copyright 2026, Leo. |
| |
//| https://www.mql5.com/es/users/nique_372/news |
| |
//+------------------------------------------------------------------+
| |
#property copyright "Copyright 2026, Leo."
| |
#property link "https://www.mql5.com/es/users/nique_372/news"
| |
#property strict
| |
| |
#ifndef TLGNEWSINFORMER_SRC_MAIN_MQH
| |
#define TLGNEWSINFORMER_SRC_MAIN_MQH
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
// Inlcuimos el manejo de event codes
| |
#include <TSN\\FastNL\\EventCodesGen.mqh>
| |
// tambien el predict event
| |
#include <TSN\\FastNL\\CentralBank.mqh>
| |
// bueno malo tambien
| |
#include <TSN\\FastNL\\BuenoMalo.mqh>
| |
// main api aqui
| |
#include <TSN\\Telegram\\MainAPI.mqh>
| |
// emojis
| |
#include <TSN\\Telegram\\Emojis.mqh>
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
enum ENUM_CALENDARFILTER_TYPE
| |
{
| |
CALENDARFILTER_NONE, // No-Filters
| |
CALENDARFILTER_TYPE_BY_CURRENT_SYMBOL, // Filter by current symbol
| |
CALENDARFILTER_TYPE_BY_COUNTRIES, // Filter by list of country codes (incluyed)
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
class CTelegramsNews : public TSN::CNewsEventsHook
| |
{
| |
private:
| |
TSN::CTelegramAPI m_bot;
| |
ulong m_country_id_a_cambiar;
| |
TSN::EconomicEventData m_events[256];
| |
| |
//---
| |
string m_symbol;
| |
| |
//---
| |
string PrediccionToStr(double pred);
| |
| |
public:
| |
CTelegramsNews();
| |
~CTelegramsNews();
| |
| |
//---
| |
inline TSN::CTelegramAPI* GetBotPtr() { return &m_bot; }
| |
| |
//---
| |
void OnTodayNews() override final;
| |
void OnNews(const TSN::EconomicEventData& events[], const int res, const datetime curr_time) override final;
| |
bool Init(const string& symbol);
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
CTelegramsNews::CTelegramsNews(void)
| |
: m_country_id_a_cambiar(0)
| |
{
| |
m_news_hooks_flags = NEWSBYLEO_HOOK_ON_NEWS | NEWSBYLEO_HOOK_ON_TODAY_NEWS;
| |
AddLogFlags(LOG_ALL);
| |
}
| |
//+------------------------------------------------------------------+
| |
CTelegramsNews::~CTelegramsNews()
| |
{
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
bool CTelegramsNews::Init(const string& symbol)
| |
{
| |
m_symbol = symbol;
| |
ulong temp;
| |
if(!TSN::GetCountryIdsBySymbol(m_symbol, m_country_id_a_cambiar, temp))
| |
return false;
| |
| |
//---
| |
LogInfo(StringFormat("CountyIdACambiar is = %d", m_country_id_a_cambiar), FUNCION_ACTUAL);
| |
return true;
| |
}
| |
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
string CTelegramsNews::PrediccionToStr(double pred)
| |
{
| |
if(pred == 10.0)
| |
{
| |
return EMOJI_CHART_UP;
| |
}
| |
else
| |
if(pred == -10.0)
| |
{
| |
return EMOJI_CHART_DOWN;
| |
}
| |
else
| |
{
| |
return EMOJI_CHART_BAR;
| |
}
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
void CTelegramsNews::OnTodayNews(void)
| |
{
| |
//---
| |
static MqlCalendarEvent desc;
| |
const int t = m_calendar.NumeroDeNoticiasToday();
| |
m_calendar.GetEventsToday(m_events);
| |
| |
//---
| |
Print("------- Events for today -------");
| |
| |
//---
| |
for(int i = 0; i < t; i++)
| |
{
| |
//---
| |
const uint meta = m_events[i].extra_meta;
| |
m_calendar.GetEventDesc(NEWSBYLEO_EXTRAMETA_GET_COUNTRY_IDX(meta),
| |
NEWSBYLEO_EXTRAMETA_GET_EVENT_IDX(meta), desc);
| |
| |
//---
| |
TSN::EconomicEventLog(m_events[i], desc);
| |
}
| |
}
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
void CTelegramsNews::OnNews(const TSN::EconomicEventData &events[], const int res, const datetime curr_time)
| |
{
| |
//---
| |
static const string ImportanciaAEmoji[4] = { EMOJI_GRAY_CIRCLE, EMOJI_GRAY_CIRCLE, EMOJI_YELLOW_CIRCLE, EMOJI_RED_CIRCLE};
| |
| |
//---
| |
const datetime time = events[0].time;
| |
string str;
| |
StringReserve(str, 1024);
| |
| |
//---
| |
str += StringFormat("📅 New news scheduled for: %s\n\n", TimeToString(time));
| |
str += "| Event | Imp | Est | Prev | Pred |\n";
| |
str += "|:-----:|:----:|:----:|:----:|:-----:|\n";
| |
| |
//---
| |
const int t = ArraySize(events);
| |
for(int i = 0; i < t; i++)
| |
{
| |
TSN::EconomicEventData evento = events[i];
| |
static MqlCalendarEvent desc;
| |
const uint meta = events[i].extra_meta;
| |
m_calendar.GetEventDesc(NEWSBYLEO_EXTRAMETA_GET_COUNTRY_IDX(meta),
| |
NEWSBYLEO_EXTRAMETA_GET_EVENT_IDX(meta), desc);
| |
| |
| |
//---
| |
const bool es_bueno_quesuba = TSN::CEnumRegFnlids::GetVal(desc.id) != NEWSBYLEO_BUENOMALO_IDX_MALO;
| |
const string mul = MultiplicadorCaledarioToString(desc.multiplier);
| |
const int idx_imp = (int)desc.importance;
| |
| |
//---
| |
const string prev_value = evento.prev_value == ERROR_VARIABLE ? "N/D" : DoubleToString(evento.prev_value, 2);
| |
| |
//--- en base al forceast decidimos
| |
if(evento.forecast_value == ERROR_VARIABLE)
| |
{
| |
str += StringFormat("| %s | %s | %s %s | %s %s | — |\n",
| |
desc.name,
| |
ImportanciaAEmoji[idx_imp],
| |
mul, "N/D",
| |
mul, prev_value
| |
);
| |
}
| |
else
| |
{
| |
str += StringFormat("| %s | %s | %s %s | %s %s | %s |\n",
| |
desc.name,
| |
ImportanciaAEmoji[idx_imp],
| |
mul, DoubleToString(evento.forecast_value, 2),
| |
mul, prev_value,
| |
PrediccionToStr(TSN::TeoricMovementOfEventUseForecast(evento,
| |
desc.country_id, m_country_id_a_cambiar, es_bueno_quesuba))
| |
);
| |
}
| |
}
| |
| |
//---
| |
str += "\n> `Pred`: expected impact on `" + m_symbol + "`";
| |
| |
//---
| |
if(!m_bot.SendRichMessageMarkdown(str, TLGBYLEO_BOOL_UNSET, TLGBYLEO_BOOL_UNSET))
| |
{
| |
LogError(StringFormat("Error call send last err TelegramByLeo lib = '%s', Last web requeset response = %d, Last MQL5 Err = %d",
| |
EnumToString(m_bot.LastErr()), m_bot.LastResHttp(), ::GetLastError()), FUNCION_ACTUAL);
| |
}
| |
}
| |
//+------------------------------------------------------------------+
| |
#endif // TLGNEWSINFORMER_SRC_MAIN_MQH
|