| //+------------------------------------------------------------------+
|
| //| NewsTraderForecast.mqh |
|
| //| Copyright 2025, Leo. |
|
| //| https://www.mql5.com/es/users/nique_372/news |
|
| //+------------------------------------------------------------------+
|
| #property copyright "Copyright 2025, Leo."
|
| #property link "https://www.mql5.com/es/users/nique_372/news"
|
| #property strict
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| #include "Global.mqh"
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| namespace TSN
|
| {
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| ICalendarByLeo* calendar;
|
| CRiskManagemet* risk;
|
|
|
| //--- Noticias que se operan de usa
|
| const string cadena_USD_operate =
|
| IPC_NAME + "," +
|
| NFP_NAME + "," +
|
| PBI_NAME + "," +
|
| FedTasaInteres_NAME + "," +
|
| Ventas_Minorista_NAME + "," +
|
| IPP_NAME + "," +
|
| ISM_PMI_MANUFACTURERO_NAME + "," +
|
| ISM_PMI_NO_MANUFACTURERO_NAME + "," +
|
| CORE_CPE + "," +
|
| JOLTS_TRABAJOS + "," +
|
| ADP_CAMBIO + "," +
|
| INDICE_CONFIANZA_CONSUMIDOR;
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| class CNewsTrader : public CStrategyBaseTemplate<CNewsEventsHook>
|
| {
|
| private:
|
| ulong country_id_profit;
|
| void OpenOrder(ENUM_POSITION_TYPE type);
|
|
|
| public:
|
| CNewsTrader(ulong magic_number_, string symbol_, ENUM_TIMEFRAMES timeframe_ = PERIOD_CURRENT, long chart_id_ = 0,
|
| int subwindow_ = 0, ulong max_deviation_ = NO_MAX_DEVIATION_DEFINED);
|
| ~CNewsTrader() {}
|
|
|
| //---
|
| void OnNews(const EconomicEventData& events[], const int res, const datetime curr_time) override final;
|
| void Set(ulong country_id_prof) { this.country_id_profit = country_id_prof;}
|
|
|
| //---
|
| void OnNewBar(const datetime curr_time) override final {}
|
| void OnTick(const datetime curr_time) override final {}
|
| };
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| CNewsTrader::CNewsTrader(ulong magic_number_, string symbol_, ENUM_TIMEFRAMES timeframe_ = PERIOD_CURRENT,
|
| long chart_id_ = 0, int subwindow_ = 0, ulong max_deviation_ = 0)
|
| : CStrategyBaseTemplate<CNewsEventsHook>(magic_number_, symbol_, timeframe_, chart_id_,
|
| subwindow_, max_deviation_, "News Trader")
|
| {
|
| m_news_hooks_flags = NEWSBYLEO_HOOK_ON_NEWS;
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| void CNewsTrader::OpenOrder(ENUM_POSITION_TYPE type)
|
| {
|
| //---
|
| ::SymbolInfoTick(m_symbol, m_tick);
|
|
|
| //---
|
| if(type == POSITION_TYPE_BUY)
|
| {
|
| double entry = m_tick.ask;
|
| double sl = GetSL(entry, type, m_tick.time);
|
| double tp = GetTP(entry, type, m_tick.time);
|
| risk.SetStopLoss(m_symbol, entry - sl);
|
| double l = m_LOT_SIZE > 0.00 ? m_LOT_SIZE : risk.GetLote(ORDER_TYPE_BUY, entry, m_max_deviation, 0);
|
| m_trade.Buy(l, m_symbol, entry, sl, tp, "Ea Buy");
|
| }
|
| else
|
| {
|
| double entry = m_tick.bid;
|
| double sl = GetSL(entry, type, m_tick.time);
|
| double tp = GetTP(entry, type, m_tick.time);
|
| risk.SetStopLoss(m_symbol, sl - entry);
|
| double l = m_LOT_SIZE > 0.00 ? m_LOT_SIZE : risk.GetLote(ORDER_TYPE_SELL, entry, m_max_deviation, 0);
|
| m_trade.Sell(l, m_symbol, entry, sl, tp, "Ea Sell");
|
| }
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| void CNewsTrader::OnNews(const EconomicEventData& events[], const int res, const datetime curr_time)
|
| {
|
| //---
|
| for(int i = 0; i < ::ArraySize(events); i++)
|
| {
|
| //---
|
| const uint meta = events[i].extra_meta;
|
| const ulong cid = m_calendar.GetEventContryId(NEWSBYLEO_EXTRAMETA_GET_COUNTRY_IDX(meta),
|
| NEWSBYLEO_EXTRAMETA_GET_EVENT_IDX(meta));
|
|
|
| //---
|
| const double pred = TeoricMovementOfEvent(events[i], cid, country_id_profit, true);
|
| if(pred > 0.0)
|
| {
|
| OpenOrder(POSITION_TYPE_BUY);
|
| }
|
| else
|
| if(pred < 0.0)
|
| {
|
| OpenOrder(POSITION_TYPE_SELL);
|
| }
|
|
|
| //--- A la primera
|
| break;
|
| }
|
| }
|
| //+------------------------------------------------------------------+
|
| }
|
| //+------------------------------------------------------------------+
|