Features of the mql5 language, subtleties and tricks - page 333

 
Stefano Cerbioni #:
Subject: Feature Request: Implement OnChartSwitch event handler for monitoring the whole terminal

Description:
Currently in MQL5, an Expert Advisor is strictly bound to the chart it is running on. There is no native, event-driven way to detect when a user switches focus (clicks) between different chart tabs in the terminal, unless the EA is present on every chart.

While a high-frequency OnTimer (e.g. 50ms) could poll CHART_BRING_TO_TOP, this is inefficient and resource consuming when managing a large number of charts.

Proposed solution:
Introduce a new event handler: void OnChartSwitch(long focusedChartID, string symbol, ENUM_TIMEFRAME period).

This event should:

Trigger every time the user clicks on another chart tab in the terminal.

Be available for any EA running in the terminal, regardless of which chart the EA is physically bound to (or at least provide a global chart property accessible via OnChartEvent).

Example Usage:

Multi-Chart Dashboards: Allows a single EA controller to synchronise external instruments (via DLL/Named Pipes) or GUI dashboards instantly when a trader navigates his Market Watch or open charts.

Dynamic Analysis: Synchronise external Order Management Systems (OMS) to the current symbol without having to pin the EA to dozens of open windows.

Benefits:
Significant reduction in CPU load compared to timer-based polling and a much more responsive "Push" architecture for modern trading setups.

1 - You can save the template after installing the EA and then apply the template to other charts

2 - You can create a service to monitor window activity