From 170ff7ea15084456d247913d064776d569e14aea Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Wed, 31 Dec 2025 17:31:02 +0100 Subject: [PATCH] docs(indicators): Optimized for incremental calculation --- Indicators/MyIndicators/AD_Pro.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Indicators/MyIndicators/AD_Pro.md b/Indicators/MyIndicators/AD_Pro.md index ce4a3d2..4f4028b 100644 --- a/Indicators/MyIndicators/AD_Pro.md +++ b/Indicators/MyIndicators/AD_Pro.md @@ -34,17 +34,15 @@ Our MQL5 implementation follows a modern, object-oriented design pattern to ensu * **Modular Calculator Engine (`AD_Calculator.mqh`):** All core calculation logic is encapsulated within a reusable include file. This separates the mathematical complexity from the indicator's user interface and buffer management. +* **Optimized Incremental Calculation (O(1)):** + Unlike basic implementations that recalculate the entire history on every tick, this indicator employs an intelligent incremental algorithm. + * **State Tracking:** It utilizes `prev_calculated` to process only new bars. + * **Persistent Buffers:** Internal buffers (High, Low, Close) persist their state between ticks. + * **Cumulative Logic:** The calculation correctly handles the running total (`ADL[i] = ADL[i-1] + MFV`) during incremental updates, ensuring that the cumulative value remains accurate without re-processing the entire history. + * **Object-Oriented Design (Inheritance):** - * A base class, `CADCalculator`, handles the core A/D algorithm. It is designed to work with any set of High, Low, and Close data it receives. - * A derived class, `CADCalculator_HA`, inherits from the base class and **overrides** only one specific function: the candle data preparation. Its sole responsibility is to calculate Heikin Ashi candles and provide the resulting HA High, Low, and Close values to the base class's A/D algorithm. This is a clean and efficient use of polymorphism. - -* **Simplified Main Indicator (`AD_Pro.mq5`):** - The main indicator file is now extremely clean. Its primary roles are: - 1. Handling user inputs (`input` variables). - 2. Instantiating the correct calculator object (`CADCalculator` or `CADCalculator_HA`) in `OnInit()` based on the user's choice. - 3. Delegating the entire calculation process to the calculator object with a single call in `OnCalculate()`. - -* **Stability via Full Recalculation:** We use a full recalculation on every tick. For a cumulative, recursive indicator like the ADL, this "brute-force" approach is the most robust method, eliminating potential errors from `prev_calculated` logic during history loading or timeframe changes. + * A base class, `CADCalculator`, handles the core A/D algorithm. + * A derived class, `CADCalculator_HA`, inherits from the base class and **overrides** only one specific function: the candle data preparation. Its sole responsibility is to calculate Heikin Ashi candles and provide the resulting HA High, Low, and Close values to the base class's A/D algorithm. ## 4. Parameters (`AD_Pro.mq5`)