Plenty of Expert Advisors are told to stay out of the market around high impact news. Many implement that with a hand maintained list of times, or by scraping a website. MT5 already ships an economic calendar that an EA can query directly, and it is enough for a simple blackout window.

Note that the calendar functions do not work in the Strategy Tester, so this filter is for live and demo trading. For backtests you need a saved list of event times.

Query upcoming events

bool InNewsBlackout(const string currency, int minutesBefore, int minutesAfter) { MqlCalendarValue values[]; datetime now = TimeTradeServer(); datetime from = now - minutesAfter * 60; datetime to = now + minutesBefore * 60; if(CalendarValueHistory(values, from, to, NULL, currency) <= 0) return false; for(int i = 0; i < ArraySize(values); i++) { MqlCalendarEvent ev; if(!CalendarEventById(values[i].event_id, ev)) continue; if(ev.importance == CALENDAR_IMPORTANCE_HIGH) return true; } return false; } 

Use both currencies of the pair

For EURUSD you care about EUR and USD events. Read them from the symbol instead of hard coding:

string base = SymbolInfoString(_Symbol, SYMBOL_CURRENCY_BASE); string profit = SymbolInfoString(_Symbol, SYMBOL_CURRENCY_PROFIT); bool blocked = InNewsBlackout(base, 30, 15) || InNewsBlackout(profit, 30, 15); 

For gold and indices the base currency is often not what moves the price, so add USD explicitly for XAUUSD and the index's home currency for indices.

Things to watch

  1. Calendar times are in trade server time, which is why the code uses TimeTradeServer rather than TimeLocal.
  2. Do not call the calendar on every tick. Cache the result for a minute; the calendar does not change that fast.
  3. Decide what the blackout means for open trades. Blocking new entries is easy. Closing or tightening existing positions is a separate decision, and it should be an input, not a hidden behaviour.
  4. Log when the filter blocks a trade, with the event name, so you can check later that it fired for the right reasons.

A blackout filter will not make a bad strategy good, but it removes one of the most common sources of surprise slippage on an otherwise reasonable EA.