- MQL5 93.6%
- MQL4 6.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| src | ||
| .gitattributes | ||
| Evolution.mq5 | ||
| README.md | ||
Evolution
This repository holds the code of the article series Modular Indicator Architecture in MQL5 by Vladislav Boyko on MQL5.com. The series builds an object-oriented framework for MetaTrader 5 custom indicators, in which an indicator is assembled from reusable modules. Each article explains its changes to the code through the commits of this repository.
| Part | Article | Code at the End of the Part |
|---|---|---|
| 1 | Stop Copy-Pasting and Start Writing Scalable, Reusable Code | article-part1 |
| 2 | Standard Smoothing Methods as Interchangeable Modules | article-part2 |
How to Follow the Articles
The code grows in single-purpose commits, and the articles explain them in the order of the history. The code snippets of an article have captions with links to the commits that the code comes from. Under each part below, a table lists the commits of each section of the article.
The tag of a part marks the code at the end of that part. The main branch has the latest code and can be ahead of the latest tag: its commits after that tag belong to no published part yet.
The Code
| File | Description |
|---|---|
Evolution.mq5 |
The main indicator file acting as the entry point and containing the MQL5 event handlers. |
src/Indicator.mqh |
The root object that wires all sub-indicators together, eliminating the need for global state. |
src/IndicatorBase.mqh |
Abstracts away infrastructure boilerplate (such as rates_total checks) from the main indicator logic. |
src/InputsAndRelated.mqh |
Defines the global input variables and CIndiParams, the derived class mapping them to the parameter object. |
src/IndiParamsBase.mqh |
Defines the base class for indicator parameters, decoupling the core logic from global input variables. |
src/SubIndiRegistry.mqh |
A static registry that centrally manages the barsRequired requirement across all modules. |
src/SubIndiBase.mqh |
The base class for all sub-indicators that extracts common traits and handles routine boilerplate. |
src/AppliedPrice.mqh |
A sub-indicator that calculates the applied price. |
src/SmoothingBase.mqh |
The base class for all smoothing sub-indicators that defines their common interface. |
src/Sma.mqh |
A sub-indicator that calculates the Simple Moving Average. |
src/Ema.mqh |
A sub-indicator that calculates the Exponential Moving Average. |
src/Smma.mqh |
A sub-indicator that calculates the Smoothed Moving Average. |
src/Lwma.mqh |
A sub-indicator that calculates the Linear Weighted Moving Average. |
Part 1: Stop Copy-Pasting and Start Writing Scalable, Reusable Code
The article develops an object-oriented framework for MQL5 indicators by evolving a primitive example into reusable modules. It formalizes partial buffer recalculation in OnCalculate, moves logic into header-based classes (CAppliedPrice, CSma), and introduces CSubIndiBase, CIndicatorBase, and a registry to centralize requirements. You get portable components, isolated inputs, and clean buffers with minimal boilerplate, making new indicators faster to assemble and easier to maintain.
Part 2: Standard Smoothing Methods as Interchangeable Modules
EMA, SMMA, and LWMA join SMA as modules of the indicator framework from Part 1, all four derived from a new base class, CSmoothingBase. The root object, CIndicator, dynamically creates the module of the chosen smoothing method and works with it through a base-class pointer. Besides the code, the article explains the smoothing methods themselves, with formulas and worked examples, and compares the four: how they weight the bars, what they need to start, and what their calculation costs.
Apart from the commits that change only this README, two commits of this part are in no section, and neither changes what the code does: docs: add code comments to all source files, before Section 1, and style: align pointer and reference symbols with type, between Sections 3 and 4.