Page 1 of 1
MQL5 Calendar Functions: CalendarValueHistory for a News Pause
Posted: Thu Oct 08, 2026 4:07 pm
by FXS Prop Desk
MT5 includes a built-in economic calendar accessible from MQL5. An EA can use it to pause trading around events.
A practical alternative for backtesting is to export historical calendar data once from an external source and load it into the EA as a file. That way the same filter logic can be tested and used live.
Key functions:
- CalendarValueHistory: get events in a time range.
- CalendarEventById: event details, including importance.
- CalendarCountryById: currency of the event.
Approach:
- At start and every few minutes, load events for the next hours.
- Filter by importance and currency.
- Block new entries X minutes before and after.
Limitations:
- Calendar data is not available in the Strategy Tester, so historical testing of the filter needs another source.
- Times are in server time.
Have you implemented a news filter using MQL5 calendar functions?
Re: MQL5 Calendar Functions: CalendarValueHistory for a News Pause
Posted: Tue Oct 13, 2026 3:06 am
by Shadow Trader
I run something similar, and the field that caught me out was the event's time_mode. Some events come through as date only or tentative with a time of midnight, so my first filter paused the EA at 00:00 server time and missed the real event.
Now anything that isn't CALENDAR_TIMEMODE_DATETIME goes into a separate list. Tentative high importance events get a log line and a manual check, and date only ones are ignored unless I've flagged them myself.
For polling, CalendarValueLast with a stored change_id is lighter than requesting the full range every few minutes. It only returns values that changed since the last call.
I'd also make the filter fail closed. If the history call returns zero events for the coming week, which happened to me once after a terminal update before the calendar synced, the EA treats it as an error and takes no new entries.
For the test file, I store times in UTC rather than server time. The server's offset to UTC changes twice a year with US daylight saving, and a UTC file means handling those dates in one place.
What window do you use? Mine is 5 minutes before and 20 after, and I wonder whether an EA pause should be longer than a discretionary one, since nobody is watching the spread.
Re: MQL5 Calendar Functions: CalendarValueHistory for a News Pause
Posted: Fri Oct 16, 2026 12:29 am
by Shadow Trader
FXS Prop Desk, the currency filter is where crosses go wrong for me. EURJPY needs both EUR and JPY high importance events, and my first version only blocked the base currency of the symbol name.
That left me trading through a Japanese CPI print because the symbol string started with EUR. Now the filter maps each symbol to a currency set, and any event in that set can pause the EA.
Importance mapping needs the same care. I treat CALENDAR_IMPORTANCE_HIGH as a hard block, and MEDIUM only for the currencies I actually scalp. Low importance never pauses anything, or the EA sits out half of Asia.
Rescheduled events are another hole. CalendarValueLast can return a changed time after I have already loaded the morning list, so I re-poll in the minute before each planned pause and rebuild the window if the timestamp moved.
For the pause length question you left open, my EA window is wider than my discretionary one: 10 minutes before and 30 after. Nobody is watching the spread, so I would rather miss a clean re-entry than wake up to a filled stop in a three pip book.
Do you also map multi-currency symbols by hand, or is there a cleaner MQL5 call I am missing?