MQL5: add timer-based command polling for live trading - #295
MQL5: add timer-based command polling for live trading#295biohazardxxx wants to merge 13 commits into
Conversation
OnTimer() (which drains the command queue via executeCommand()) was only called from OnTick() during backtesting. In live trading, commands from the .NET client would queue up and never be processed until the next market tick arrived, making the EA unresponsive on low-volume symbols or outside market hours. - Add EventSetMillisecondTimer(100) in init() for live trading mode - Call OnTimer() on every tick regardless of mode (supplements the timer) - Add EventKillTimer() in deinit() for cleanup Co-Authored-By: Claude Opus 4.6 <[email protected]>
The .ex5 binary was stale and still referenced removed DLL imports (getIntValue, getDoubleValue, etc.) that no longer exist in MT5Connector.dll since the migration to the JSON payload-based protocol (getPayload). This caused "unresolved import function call" errors when loading the EA in MetaTrader. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Fix is correct and addresses a real problem — we confirmed that without the timer, commands hang indefinitely on low-volume symbols outside market hours. Note: MQL4 ( |
New input CommandPollingIntervalMs (default 100, clamped to 10-1000) controls the EventSetMillisecondTimer interval used for command polling in live trading. Lowering it bounds worst-case command latency when the connector's PostMessage nudge is missed; the drain loop is a cheap no-op when the queue is empty. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Pushed b512562: the polling interval is now configurable via a new |
|
Measured side-effect of the polling timer, found while runtime-testing #311: with EventSetMillisecondTimer active, the connector's PostMessage(WM_TIMER) nudge no longer wakes the expert — every command then waits for the next timer tick. Sequential commands measured at exactly 100.0 ms/command on this branch's EA vs 0.6 ms/command on an upstream-based EA (no timer, nudge-driven) against the same connector DLL on the same terminal. Likely cause: once a real EventSetTimer is registered, MT5 filters posted WM_TIMER messages (timer-id mismatch). The new CommandPollingIntervalMs input mitigates (10 ms → ~10 ms/cmd worst case), and #310 (async pipelining) restores throughput (20 commands in one tick, measured x19.6). A cleaner long-term fix may be nudging via a chart custom event (EventChartCustom/CHARTEVENT_CUSTOM) instead of WM_TIMER so the nudge and the safety-net timer coexist. |
…ing for live trading # Conflicts: # mq5/MtApi5.ex5
Summary
OnTimer()(which drains the command queue) was only called fromOnTick()during backtesting. Commands from the .NET client would queue up and never be processed until the next market tick, making the EA unresponsive on low-volume symbols or outside market hours.EventSetMillisecondTimer(100)ininit()for live trading mode so commands are polled every 100ms regardless of tick activity.OnTimer()is now also called on every tick (supplements the timer for lowest latency when ticks are flowing).EventKillTimer()indeinit()for proper cleanup.Test plan
MtApi5.mq5with MetaEditor — verified 0 errors, 0 warningsOnTick()still callsOnTimer())🤖 Generated with Claude Code