refactor: Optimized for incremental calculation

This commit is contained in:
Toh4iem9
2025-12-06 20:44:44 +01:00
parent cacc13f429
commit 2c0ed6b120
@@ -34,8 +34,12 @@ The calculation is a complex, multi-stage digital signal processing pipeline:
## 3. MQL5 Implementation Details
* **Self-Contained Calculator (`MAMA_Calculator.mqh`):** The entire complex, multi-stage, and highly state-dependent calculation is encapsulated within a dedicated, reusable calculator class.
* **Heikin Ashi Integration:** An inherited `_HA` class allows the calculation to be performed seamlessly on smoothed Heikin Ashi data, leveraging our optimized `HeikinAshi_Tools` library.
* **Stability via Full Recalculation:** The MAMA algorithm is one of the most state-dependent filters in technical analysis. To ensure absolute stability and prevent desynchronization errors (especially with the phase measurement), the indicator employs a **full recalculation** on every `OnCalculate` call. This is the only robust method for this type of complex DSP filter.
* **Optimized Incremental Calculation:**
Unlike basic implementations that recalculate the entire history on every tick, this indicator employs an intelligent incremental algorithm.
* It utilizes the `prev_calculated` state to determine the exact starting point for updates.
* **Persistent State:** The internal buffers for the Homodyne Discriminator (`m_I1_buf`, `m_Q1_buf`, etc.) and the phase measurement persist their state between ticks. This allows the complex DSP pipeline to continue seamlessly from the last known values without re-processing the entire history.
* This results in **O(1) complexity** per tick, ensuring instant updates and zero lag, even on charts with extensive history.
* **Heikin Ashi Integration:** An inherited `_HA` class allows the calculation to be performed seamlessly on smoothed Heikin Ashi data, leveraging the same optimized engine.
## 4. Parameters