From 345d5a046d16200386bf9d9baed9f7ee655ca3de Mon Sep 17 00:00:00 2001 From: Toh4iem9 Date: Mon, 1 Dec 2025 16:17:39 +0100 Subject: [PATCH] refactor: Optimized for incremental calculation --- Indicators/MyIndicators/Supertrend_Pro.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Indicators/MyIndicators/Supertrend_Pro.md b/Indicators/MyIndicators/Supertrend_Pro.md index 2e86fd6..81a3862 100644 --- a/Indicators/MyIndicators/Supertrend_Pro.md +++ b/Indicators/MyIndicators/Supertrend_Pro.md @@ -1,4 +1,4 @@ -# Supertrend Professional +# Supertrend Pro ## 1. Summary (Introduction) @@ -34,12 +34,16 @@ Our MQL5 implementation follows a modern, component-based, object-oriented desig * **Component-Based Design:** The `Supertrend_Calculator` **reuses** our existing, standalone `ATR_Calculator.mqh` module, ensuring the ATR component is always our robust, definition-true Wilder's ATR. +* **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 recursive "stair-step" logic (`m_upper`, `m_lower`, `m_trend`) 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. + * **Object-Oriented Logic:** An elegant inheritance model (`CSupertrendCalculator` and `CSupertrendCalculator_HA`) allows the indicator to seamlessly switch between standard and Heikin Ashi price data for its core logic. * **Clean Gapped-Line Drawing:** To provide a clear visual separation at trend changes, the indicator uses a **"double buffer" technique**. It plots uptrend and downtrend segments on two separate, overlapping plot buffers. This creates a distinct visual gap when the trend flips, accurately representing the signal without drawing misleading connecting lines. -* **Stability via Full Recalculation:** We employ a "brute-force" full recalculation within `OnCalculate` for maximum stability. - ## 4. Parameters * **ATR Period (`InpAtrPeriod`):** The lookback period for the ATR calculation. Default is `10`.