Structuring an MQL5 Trading Indicator with MVC Components
Summary
This article explains how to organize an MQL5 indicator around Model, View, and Controller components, focusing on how the components exchange data and responsibilities. Its example is a Williams Percent Range indicator, chosen to demonstrate software structure rather than provide a trading method; the article explicitly says the example is not suitable for real trading.
The Controller handles user inputs and other source data. An input manager validates values, applies defaults or reports invalid settings, converts distances into price units, and retrieves terminal data such as chart background color. Other components receive a read-only base interface, while the Controller retains methods for initialization and updates. The article also discusses separating input parameters from terminal data, composing additional data modules, and using shared lifecycle methods or interfaces. These are architectural recommendations illustrated through code examples, not empirical trading results; the treatment is partial, and the described design may add complexity that is unnecessary for simple indicators.
Key ideas
- MVC separates display, data processing, and user interaction into distinct components.
- A Controller-side input manager can validate and convert parameters before other components use them.
- Terminal-sourced values can be gathered and refreshed through the same Controller-managed data flow.
- Expose a restricted base interface to other components to prevent unintended initialization or updates.
- Separate source-data modules and shared lifecycle interfaces may help as an application grows.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.