Stabilizing a Market Replay Service Through Indicator Lifecycle Events
Summary
This installment improves a MetaTrader 5 market replay tool by handling failures around its chart control indicator. The service depends on a terminal global variable shared with the indicator; when the indicator is removed or its chart closes, deinitialization handling deletes that variable so the service can stop and clean up its replay chart. The indicator also requests chart object deletion events so it can detect when users remove parts of its controls, while suppressing those events during intentional cleanup.
The article further describes preserving replay state across chart period changes by reading and updating the shared variable. Its evidence is implementation guidance and a demonstration video, rather than measured stability results. The author warns that the method covers only some misuse and failure cases, and that the separate read and write operations leave a race window in which the service may overwrite or observe inconsistent state. That limitation may matter more in systems where shared values are critical.
Key ideas
- The replay service uses a terminal global variable as a communication link with its chart control indicator.
- Removing the indicator or closing its chart can trigger cleanup that stops the service and closes replay resources.
- Chart object deletion notifications help detect removal of controls, but must be managed around intentional object cleanup.
- The shared-variable update has a race window because reading and writing are not atomic.
- The changes reduce some failure modes but do not make the replay system fully robust.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.