The Supertrend indicator, developed by Olivier Seban, is a simple yet effective trend-following indicator. Plotted directly on the price chart, the Supertrend line changes color and position based on the market's trend, acting as a dynamic level of support or resistance.
Our `Supertrend_Pro` implementation is a unified, professional version that combines three distinct calculation methodologies into a single, flexible indicator:
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.
* **ATR Period (`InpAtrPeriod`):** The lookback period for the ATR calculation. Default is `10`.
* **Factor (`InpFactor`):** The multiplier applied to the ATR value. Default is `3.0`.
* **Candle Source (`InpCandleSource`):** Determines the source for the Supertrend's price component (`(High+Low)/2` and `Close`).
* **ATR Source (`InpAtrSource`):** Determines the source for the ATR calculation (`Standard` or `Heikin Ashi`), allowing you to create "Hybrid" or "Pure" HA versions.
## 5. Usage and Interpretation
* **Trend Identification:** A green line below the price indicates an uptrend. A red line above the price indicates a downtrend.
* **Trailing Stop-Loss:** The indicator is exceptionally well-suited for use as a trailing stop-loss.
* **Trade Signals:** A change in the indicator's color can be interpreted as a trade signal.
* **Caution:** Like all trend-following indicators, Supertrend is most effective in trending markets. In sideways or ranging markets, it can produce frequent false signals ("whipsaws").