Skip to content

MtApi5: expose MT5 economic calendar (Calendar* functions)#301

Open
biohazardxxx wants to merge 9 commits into
vdemydiuk:devfrom
biohazardxxx:feat/mql5-calendar-upstream
Open

MtApi5: expose MT5 economic calendar (Calendar* functions)#301
biohazardxxx wants to merge 9 commits into
vdemydiuk:devfrom
biohazardxxx:feat/mql5-calendar-upstream

Conversation

@biohazardxxx

Copy link
Copy Markdown

Summary

Surfaces the MT5 terminal's built-in economic calendar through the MtApi5 connector. MQL5 exposes the calendar natively (CalendarValueHistory, CalendarEventById, CalendarValueLast, …) but none of it was reachable from the .NET client. This adds all 10 native Calendar* functions end-to-end.

What's included

C# client (MtApi5) — 10 methods on MtApi5Client:

Command id Method
307 CalendarCountries()
308 CalendarCountryById(long, out MqlCalendarCountry)
309 CalendarEventById(long, out MqlCalendarEvent)
310 CalendarEventByCountry(string)
311 CalendarEventByCurrency(string)
312 CalendarValueById(long, out MqlCalendarValue)
313 CalendarValueHistoryByEvent(long, DateTime, DateTime)
314 CalendarValueHistory(DateTime, DateTime, string, string)
315 CalendarValueLastByEvent(long, ref long)
316 CalendarValueLast(ref long, string, string)
  • New DTOs MqlCalendarCountry, MqlCalendarEvent, MqlCalendarValue and 8 ENUM_CALENDAR_* enums (values verified against the official MQL5 reference).
  • MqlCalendarValue keeps the raw wire fields (long, ×1e6, LONG_MIN = "no value") and adds convenience double? accessors (ActualValue/ForecastValue/PrevValue/RevisedPrevValue, null when empty) plus DateTime time/period.
  • Single-item getters use the native bool + out idiom; CalendarValueLast* round-trip the in/out change_id via ref long.

MQL5 EA (mq5/MtApi5.mq5) — 10 Execute_Calendar* handlers + executor registrations + 3 JSON serializers. 64-bit ids / datetimes / scaled values use the existing GET_ULONG/GET_LONG macros and JSONNumber((long)). mq5/MtApi5.ex5 recompiled (0 errors, 0 warnings).

TestClient — a CalendarHistory button for manual exercising.

Testing

Verified against a live MT5 terminal:

  • CalendarCountries (23), CalendarEventByCurrency("USD") / CalendarEventByCountry("US") (248), CalendarEventById (correct event, 64-bit id intact), CalendarValueHistory (decodes correctly; LONG_MINnull; enums decode to HIGH/PRICES/PERCENT etc.), CalendarValueById (sentinel handling), CalendarValueLastByEvent (change_id round-trips), and CalendarEventById(0)false without throwing.

Branch is based on dev and contains calendar changes only.

biohazardxxx and others added 9 commits July 2, 2026 11:37
Values verified against the official MQL5 mqlcalendar reference
(member order 0-based for all 8 enums).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Native CalendarCountryById/EventById/ValueById set a nonzero LastError even for
a simple not-found, which made the handlers emit an error response. Native
contract is a plain bool, so map any false to a null Value (client bool=false).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Compiled on the upstream/dev base (0 errors, 0 warnings).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
hosseinkhojany pushed a commit to hosseinkhojany/mtapi that referenced this pull request Jul 22, 2026
…ar* functions

# Conflicts:
#	mq5/MtApi5.ex5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant