mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-26 02:38:05 +00:00
refactor: Refactored to use Composition Pattern
This commit is contained in:
@@ -35,22 +35,19 @@ This indicator analyzes the behavior of two underlying indicators, AMA and ATR,
|
|||||||
|
|
||||||
## 3. MQL5 Implementation Details
|
## 3. MQL5 Implementation Details
|
||||||
|
|
||||||
Our MQL5 implementation follows a modern, object-oriented design pattern to ensure stability, reusability, and maintainability. The logic is separated into a main indicator file and a dedicated calculator engine.
|
Our MQL5 implementation follows a modern, object-oriented design pattern to ensure stability, reusability, and maintainability.
|
||||||
|
|
||||||
* **Modular Calculator Engine (`AMA_TrendActivity_Calculator.mqh`):**
|
* **Modular Calculator Engine (`AMA_TrendActivity_Calculator.mqh`):**
|
||||||
All core calculation logic is encapsulated within a reusable include file. This separates the complex, five-step mathematical process from the indicator's user interface and buffer management.
|
All core calculation logic is encapsulated within a reusable include file.
|
||||||
|
|
||||||
* **Object-Oriented Design (Inheritance):**
|
* **Composition Pattern:**
|
||||||
* A base class, `CActivityCalculator`, handles the **entire shared calculation chain** (AMA, ATR, Raw Activity, Arctan, and SMA smoothing).
|
Instead of complex inheritance trees, the `CActivityCalculator` class uses **composition**. It internally owns and manages instances of the standard `CAMACalculator` and `CATRCalculator`. This ensures that the Activity indicator uses exactly the same mathematical logic as the standalone AMA and ATR indicators, guaranteeing consistency.
|
||||||
* A derived class, `CActivityCalculator_HA`, inherits from the base class and **overrides** only one specific function: the preparation of all source data. Its sole responsibility is to calculate Heikin Ashi candles and provide the resulting HA data to the base class's calculation pipeline for both the AMA and ATR components. This is a clean and efficient use of polymorphism.
|
|
||||||
|
|
||||||
* **Simplified Main Indicator (`AMA_TrendActivity_Pro.mq5`):**
|
* **Optimized Incremental Calculation (O(1)):**
|
||||||
The main indicator file is now extremely clean. Its primary roles are:
|
Unlike basic implementations that recalculate the entire history on every tick, this indicator employs a sophisticated incremental algorithm.
|
||||||
1. Handling user inputs (`input` variables).
|
* **Persistent State:** The calculator maintains internal buffers (`m_buffer_ama`, `m_buffer_atr`, `m_scaled_activity`) that persist their state between ticks.
|
||||||
2. Instantiating the correct calculator object (`CActivityCalculator` or `CActivityCalculator_HA`) in `OnInit()` based on the user's choice.
|
* **Smart Updates:** The calculation logic (AMA -> ATR -> Activity -> Smoothing) is broken down into steps, each capable of resuming from the last calculated bar (`prev_calculated`).
|
||||||
3. Delegating the entire calculation process to the calculator object with a single call in `OnCalculate()`.
|
* This results in **O(1) complexity** per tick, ensuring instant updates and zero lag, even on charts with extensive history.
|
||||||
|
|
||||||
* **Stability via Full Recalculation:** We use a full recalculation on every tick. For a complex, multi-stage, and recursive indicator like this, the "brute-force" approach is the most robust method.
|
|
||||||
|
|
||||||
## 4. Parameters (`AMA_TrendActivity_Pro.mq5`)
|
## 4. Parameters (`AMA_TrendActivity_Pro.mq5`)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user