Hello, I am trying to integrate the Economic Calendar into my MT5 EA !

 
Hello
I am trying to integrate an economic calendar into my MT5 EA so that the robot temporarily blocks trading before important news events. I am using the stub function EconomicNewsGetNext(), but I keep getting compilation errors like:

- Undeclared identifier
- Implicit conversion from unknown to string
- [array required]

I tried the examples from the MQL5 articles ("Trading with the MQL5 Economic Calendar"), but I still get errors.

Here is the relevant EA code snippet I use to handle news:

Economic calendar parameters
input bool UseEconomicCalendar = true;
enter int NewsBlockMinutes = 5; Block trades ± 5 minutes around news
input bool ClosePositionsOnHighNews = true;

News stub functions (currently placeholders)
bool IsNewsWindowActive() { return(false); }
bool EconomicNewsGetNext(datetime & newsTime, string & currency, int & importance, string & text) { return(false); }
void CloseUnfavorablePositionsAfter News(datetime newsTime, double atr) { }

Using OnTick():
if(UseEconomicCalendar & IsNewsWindowActive()) return;

if(UseEconomicCalendar & ClosePositionsOnHighNews)
{
datetime newsTime; string currency; int importance; string text;
if(EconomicNewsGetNext( newsTime, currency, importance, text))
{
CloseAdverse positionsAfter news(newsTime, atr);
}
}

My goals are as follows:
1. Get real-time news timing, importance and currency.
2. Block the EA ±N minutes before/after the news event.
3. Close existing positions if the news is very important.

Question:
How to properly connect the economic calendar to the MT5 EA so that it works in real time without compilation errors? Is there a simple code example that can be integrated into the EA?

Thanks for your help!

 
82106578:
Hello
I am trying to integrate an economic calendar into my MT5 EA so that the robot temporarily blocks trading before important news events. I am using the stub function EconomicNewsGetNext(), but I keep getting compilation errors like:

- Undeclared identifier
- Implicit conversion from unknown to string
- [array required]

I tried the examples from the MQL5 articles ("Trading with the MQL5 Economic Calendar"), but I still get errors.

Here is the relevant EA code snippet I use to handle news:

Economic calendar parameters
input bool UseEconomicCalendar = true;
enter int NewsBlockMinutes = 5; Block trades ± 5 minutes around news
input bool ClosePositionsOnHighNews = true;

News stub functions (currently placeholders)
bool IsNewsWindowActive() { return(false); }
bool EconomicNewsGetNext(datetime & newsTime, string & currency, int & importance, string & text) { return(false); }
void CloseUnfavorablePositionsAfter News(datetime newsTime, double atr) { }

Using OnTick():
if(UseEconomicCalendar & IsNewsWindowActive()) return;

if(UseEconomicCalendar & ClosePositionsOnHighNews)
{
datetime newsTime; string currency; int importance; string text;
if(EconomicNewsGetNext( newsTime, currency, importance, text))
{
CloseAdverse positionsAfter news(newsTime, atr);
}
}

My goals are as follows:
1. Get real-time news timing, importance and currency.
2. Block the EA ±N minutes before/after the news event.
3. Close existing positions if the news is very important.

Question:
How to properly connect the economic calendar to the MT5 EA so that it works in real time without compilation errors? Is there a simple code example that can be integrated into the EA?

Thanks for your help!

When you post code please use the CODE button (Alt-S) !  

Traders and coders are working for free:

  • if it is interesting for them personally, or
  • if it is interesting for many members on this forum.

Freelance section of the forum should be used in most of the cases.

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2025.11.17
  • www.mql5.com
The largest freelance service with MQL5 application developers