mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-05 00:27:44 +00:00
refactor: Optimized for incremental calculation
This commit is contained in:
@@ -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`.
|
||||
|
||||
Reference in New Issue
Block a user