The Vortex Indicator (VI), developed by Etienne Botes and Douglas Siepman, is a trend-following indicator designed to identify the start and direction of a new trend. It consists of two oscillating lines: a positive trend indicator (+VI) and a negative trend indicator (-VI).
The indicator's strength lies in its clear visual signals, which are generated by the crossover of its two lines. It is often used as an alternative or a confirmation tool for other trend systems like the ADX/DMI.
Our `Vortex_Pro` implementation is a unified, professional version that allows the calculation to be based on either **standard** or **Heikin Ashi** price data, selectable from a single input parameter.
## 2. Mathematical Foundations and Calculation Logic
The VI is calculated by summing the "vortex movements" and the True Range over a specified period.
### Required Components
* **Period (N):** The lookback period for the summation (default is 21 or 14).
* **Price Data:** The `High`, `Low`, and `Close` of each bar.
### Calculation Steps (Algorithm)
1.**Calculate True Range (TR) and Vortex Movements (VM):** For each bar, calculate:
The entire calculation logic is encapsulated within a reusable include file.
* **`CVortexCalculator`**: The base class that performs the full VI calculation on a given set of High, Low, and Close prices.
* **`CVortexCalculator_HA`**: A child class that inherits all logic and only overrides the initial data preparation step to use smoothed Heikin Ashi prices.
Unlike basic implementations that recalculate the entire history on every tick, this indicator employs an intelligent incremental algorithm.
* **State Tracking:** It utilizes `prev_calculated` to process only new bars.
* **Persistent Buffers:** Internal buffers (TR, VM+, VM-) persist their state between ticks.
* **Sliding Window:** The summation over the lookback period is handled by an efficient sliding window logic (`sum += new_value; sum -= old_value;`), which is significantly faster than recalculating the sum on every bar.
* **Period (`InpPeriod`):** The lookback period for the summation. Common values are `14` or `21`.
* **Candle Source (`InpCandleSource`):** Allows the user to select the candle type for the calculation (`Standard` or `Heikin Ashi`).
## 5. Usage and Interpretation
* **Trend Direction (Crossovers):** The primary signal is the crossover of the two lines.
* **Bullish Signal:** The **+VI line (blue)** crosses **above** the **-VI line (red)**, indicating that buying pressure is taking control.
* **Bearish Signal:** The **+VI line (blue)** crosses **below** the **-VI line (red)**, indicating that selling pressure is dominant.
* **Trend Confirmation (1.0 Level):** The 1.0 level acts as a key threshold for trend strength.
* A trend is considered strong and confirmed when the dominant line (the one on top after a crossover) moves **above the 1.0 level**.
* **Ranging Markets:** When both lines are fluctuating below the 1.0 level and crossing frequently, it signals a sideways or non-trending market.
* **Caution:** The Vortex Indicator is a trend-following tool. Its SMA-like calculation basis can cause it to lag on lower timeframes. It is most effective for confirming the start of a new, sustained trend rather than catching the exact turning point.