refactor: Optimized for incremental calculation

This commit is contained in:
Toh4iem9
2025-12-01 16:17:39 +01:00
parent ba99bc7223
commit 345d5a046d
+7 -3
View File
@@ -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`.