Discussing the article: "Interactive Supply and Demand Zone Manager in MQL5 (Part II): Event-Driven Architecture and Persistent Lifecycle Logging"

 

Check out the new article: Interactive Supply and Demand Zone Manager in MQL5 (Part II): Event-Driven Architecture and Persistent Lifecycle Logging.

This article advances the stateful supply and demand zone framework for MetaTrader 5 by replacing polling with an event-driven model based on OnChartEvent(). We split synchronization into dedicated handlers for creation, modification, and deletion, and separate market logic in OnTick() from user interactions in OnChartEvent(). A persistent, append-only CSV logger records all lifecycle events, improving responsiveness, state consistency, and recoverable history for downstream analysis.

In Part I of this series, we introduced a dynamic supply and demand zone management framework capable of transforming ordinary chart rectangles into actively managed market structures. Rather than treating support and resistance zones as passive visual annotations, we developed a system capable of creating, maintaining, merging, invalidating, and restoring structural regions as market conditions evolved.

The primary objective of the initial implementation was to establish the concept of a stateful zone. Each zone was no longer treated as a simple graphical object, but as a structured entity containing attributes such as classification, status, origin, strength, and interaction history. Within this model, a support level could transition from a newly created state into a broken state, while a previously invalidated structure could be retained in a ghosted form rather than immediately removed. Under defined conditions, such a zone could later be reactivated and restored to active status. This established the foundation of lifecycle-aware support and resistance management.

However, a fundamental limitation remained. Although the framework was capable of responding to runtime events, it did not retain a persistent record of those transitions. Manual modifications, such as resizing a zone, existed only in volatile memory. Similarly, structural transitions such as breakouts or invalidations were correctly applied in real time, but no durable representation of these events was preserved. As a result, once the terminal session ended or the chart was refreshed, the full operational history was lost. The system retained only the latest state of each zone, without any trace of how that state had been reached.


Author: Francis Nyoike Thumbi