The Average True Range (ATR) is a technical analysis indicator developed by J. Welles Wilder. The ATR is not used to indicate price direction; rather, it is a measure of **volatility**.
It calculates the "true range" for each period and then smooths these values, providing a representation of the average size of the price range. High ATR values indicate high volatility, while low ATR values indicate low volatility.
Our `ATR_Pro` implementation is a unified, professional version that allows the calculation to be based on either **standard** or **Heikin Ashi** candles. Furthermore, it can display the ATR value in two modes:
* **Points:** The classic representation, showing the absolute volatility in price points.
* **Percent:** A normalized value, showing the ATR as a percentage of the closing price, which is useful for comparing volatility across different instruments.
2.**Calculate the Average True Range (ATR):** The ATR is a smoothed moving average of the TR values, calculated using Wilder's specific smoothing method (RMA/SMMA).
3.**Normalize to Percentage (Optional):** If the user selects the "Percent" display mode, the final ATR value is converted to a percentage of the closing price.
* **Modular Calculation Engine (`ATR_Calculator.mqh`):** All core calculation logic is encapsulated within a reusable include file. The engine now includes a final, optional step to convert the result to a percentage based on a user-selected mode.
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 (like `m_tr` and `m_atr_raw`) persist their state between ticks. This allows the recursive Wilder's Smoothing algorithm 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 Design (Inheritance):** A base class, `CATRCalculator`, handles the shared Wilder's smoothing algorithm. A derived class, `CATRCalculator_HA`, overrides only the initial calculation of the raw True Range values to use Heikin Ashi candles.
* **ATR Period (`InpAtrPeriod`):** The lookback and smoothing period for the indicator. Wilder's original recommendation is `14`.
* **Display Mode (`InpDisplayMode`):** Allows the user to select the output format.
*`ATR_POINTS`: Displays the ATR in absolute price points (default).
*`ATR_PERCENT`: Displays the ATR as a percentage of the closing price.
* **Candle Source (`InpCandleSource`):** Allows the user to select the candle type for the True Range calculation (`CANDLE_STANDARD` or `CANDLE_HEIKIN_ASHI`).
* **Volatility Gauge:** A rising ATR indicates that volatility is increasing. A falling ATR indicates that volatility is decreasing.
* **Stop-Loss Placement:** ATR is a cornerstone of risk management. A common technique is to place a stop-loss at a multiple of the ATR (e.g., 2 x ATR) from an entry price.
* **Position Sizing:** ATR can be used to normalize position sizes across different instruments.
* **Cross-Market Volatility Comparison (Percent Mode):** The "Percent" mode is exceptionally useful for comparing the relative volatility of different instruments. For example, you can objectively determine if `EURUSD` (with a 0.5% ATR) is currently more or less volatile than `Gold` (with a 1.2% ATR), regardless of their different price levels.
* **Caution:** ATR does not provide any information about trend direction.