From e66c4c0770689ae38e7cf4cb78eabd25fec2120a Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Sun, 30 Nov 2025 15:24:21 +0100 Subject: [PATCH] refactor: Optimized for incremental calculation --- Indicators/MyIndicators/VWAP_Pro.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Indicators/MyIndicators/VWAP_Pro.md b/Indicators/MyIndicators/VWAP_Pro.md index 0a6474c..f2e15c3 100644 --- a/Indicators/MyIndicators/VWAP_Pro.md +++ b/Indicators/MyIndicators/VWAP_Pro.md @@ -1,4 +1,4 @@ -# Volume Weighted Average Price (VWAP) Professional +# Volume Weighted Average Price (VWAP) Pro ## 1. Summary (Introduction) @@ -39,6 +39,12 @@ Our MQL5 implementation follows a modern, object-oriented design to ensure stabi * **Modular Calculation Engine (`VWAP_Calculator.mqh`):** The entire calculation logic is encapsulated within a reusable `CVWAPCalculator` class. This engine uses an elegant, object-oriented inheritance model (`CVWAPCalculator` and `CVWAPCalculator_HA`) to support both standard and Heikin Ashi data sources without code duplication. +* **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 cumulative variables (`m_cumulative_tpv`, `m_cumulative_vol`) persist their state between ticks. This allows the calculation to continue seamlessly from the last known value 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. + * **Flexible and Robust Period Reset Logic:** The calculator uses `MqlDateTime` structures to accurately detect the start of a new period. * For **Daily, Weekly, and Monthly** periods, it tracks the change in day, week, or month. * For **Timezone-Shifted Daily** periods, it applies a user-defined hour offset to each bar's timestamp before checking for the day change. @@ -48,8 +54,6 @@ Our MQL5 implementation follows a modern, object-oriented design to ensure stabi * **Intelligent Volume Handling:** The indicator automatically detects if the selected instrument provides **Real Volume**. If a user requests Real Volume on a symbol where it's unavailable (like Forex/CFDs), the indicator will fail to load and print an informative error message. -* **Stability via Full Recalculation:** We employ a full recalculation within `OnCalculate` for maximum stability and accuracy. - ## 4. Parameters * **Period Settings:**