MtApi5: OnChartEvent forwarding and EventChartCustom#306
Open
biohazardxxx wants to merge 6 commits into
Open
Conversation
… 385 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ogging Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Escape sparam in OnChartEvent before serialization: JSONString::toString() in mq5/json.mqh performs no escaping, so an sparam containing a double quote produced malformed JSON (event silently dropped in the C# client) and backslashes were corrupted on deserialization. Escape backslash first, then quote and control characters, mirroring the mq4 call-site pattern. Recompiled MtApi5.ex5. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Forwards the MQL5
OnChartEventhandler to the .NET client and exposes the nativeEventChartCustom()function. Chart interaction events (clicks, key presses, object edits) and custom events were previously invisible to MtApi5 applications; this adds both directions end-to-end, so a .NET client can send a custom event to a chart and receive it (or any built-in chart event) back.New API surface on
MtApi5Client:public event EventHandler<Mt5ChartEventArgs>? OnChartEvent— raised for every chart event forwarded by the EA.Mt5ChartEventArgscarriesint ExpertHandle,int EventId,long Lparam,double Dparam,string Sparam.public bool EventChartCustom(long chartId, ushort customEventId, long lparam, double dparam, string sparam)— wraps the native MQL5 function; the event is delivered back throughOnChartEventwithEventId = CHARTEVENT_CUSTOM (1000) + customEventId(documented in the XML doc and the mq5 comments).Implementation notes
Mt5CommandType.EventChartCustom) with matchingADD_EXECUTOR(385, EventChartCustom)in the EA; event type 6 (Mt5EventTypes.OnChartEvent/ON_CHART_EVENT).MtApi5/MtProtocol/OnChartEvent.cs(internal class OnChartEvent), following the existingOnBookEventnaming pattern — the internal DTO and the same-named public event coexist exactly like the existingOnBookEventpair.{EventId, Lparam, Dparam, Sparam}.ExpertHandlereaches C# via the event transport parameter and is set onMt5ChartEventArgsfrom there (OnLastTimeBarEventduplicates it in the payload but never reads it; that redundancy was not replicated).input bool Enable_OnChartEvent = trueto the EA's "Disable Events" input group, mirroring every other forwarded event's toggle, so chatty chart events can be muted.CustomEventIdis sent asintin JSON and cast toushortin the EA; the C# signature usesushortto match the native function.JSONString::toString()inmq5/json.mqhperforms no escaping (while the parser does unescape on read), sosparamis escaped manually at theOnChartEventcall site (backslash first, then quote,\n,\r,\t) before serialization — mirroring the existing mq4 call-site workaround pattern. Without this, chart events whoseSparamcontains a quote would be silently dropped and backslash sequences would corrupt.EventChartCustomtest action plusOnChartEventlogging for manual exercising.ushort/int/longmarshaling, handler signatures) and found no wiring defects; theSparamescaping fix above was the one finding it produced.Testing
MtApi5andMtApi5TestClientbuild clean (Release).mq5/MtApi5.mq5compiles via MetaEditor with "Result: 0 errors"; the recompiledmq5/MtApi5.ex5is committed.🤖 Generated with Claude Code