# Chaikin A/D Line Professional

## 1. Summary (Introduction)

The Chaikin Accumulation/Distribution (A/D) Line, developed by Marc Chaikin, is a cumulative, volume-weighted indicator designed to measure the underlying buying and selling pressure in a market. It is often referred to as the Volume Accumulator.

Unlike simpler volume indicators like On-Balance Volume (OBV) which use the direction of the bar's close, the A/D Line operates on a more nuanced principle: it determines the degree of accumulation or distribution by looking at where the price closes relative to its high-low range for the period.

* A close in the upper half of the bar's range suggests **accumulation** (buying pressure).
* A close in the lower half of the bar's range suggests **distribution** (selling pressure).

The A/D Line accumulates these volume-weighted values over time, creating a running total that can provide early warnings of trend changes through divergence.

## 2. Mathematical Foundations and Calculation Logic

The indicator is built by accumulating the "Money Flow Volume" for each bar.

### Required Components

* **Price Data:** The `High`, `Low`, and `Close` of each bar.
* **Volume (V):** The volume for each bar.

### Calculation Steps (Algorithm)

1. **Calculate the Money Flow Multiplier (MFM):** This value ranges from -1 to +1 and determines the proportion of the bar's volume to be used.
    * $\text{MFM}_t = \frac{(\text{Close}_t - \text{Low}_t) - (\text{High}_t - \text{Close}_t)}{\text{High}_t - \text{Low}_t}$
    * *(If High equals Low, the multiplier is 0).*

2. **Calculate the Money Flow Volume (MFV):** The multiplier is applied to the bar's volume.
    * $\text{MFV}_t = \text{MFM}_t \times V_t$

3. **Calculate the A/D Line:** The A/D Line is the cumulative sum of the Money Flow Volume.
    * $\text{A/D}_t = \text{A/D}_{t-1} + \text{MFV}_t$

## 3. MQL5 Implementation Details

* **Modular Calculation Engine (`Chaikin_AD_Calculator.mqh`):** All mathematical logic is encapsulated in a dedicated include file.

* **Stable Calculation:** The calculator uses a full recalculation loop with an internal state variable (`prev_ad`) to ensure the cumulative line is always accurate and stable.

* **Platform-Aware Features:**
  * **Volume Type:** The user can select between `Tick Volume` and `Real Volume` via an input parameter. The indicator robustly checks if Real Volume is available for the symbol and fails to initialize if it is not, preventing silent errors.
  * **Heikin Ashi Integration:** The standard `_HA` derived class architecture is used to seamlessly support calculations on Heikin Ashi price data.

## 4. Parameters

* **Volume Type (`InpVolumeType`):** Allows the user to select the volume source for the calculation (`VOLUME_TICK` or `VOLUME_REAL`).
* **Candle Source (`InpCandleSource`):** Allows the user to select the candle type for the calculation (`Standard` or `Heikin Ashi`).

## 5. Usage and Interpretation

The primary and most powerful signal generated by the Chaikin A/D Line is **divergence**. The absolute value of the A/D line is not important; only its direction and relationship to price are.

### 1. Bullish Divergence (A Leading Buy Signal)

* **Pattern:** The price makes a **new lower low**, but the **A/D Line fails to make a new low** and instead forms a higher low.
* **Interpretation:** This is a classic sign of **accumulation**. It suggests that even as the price is pushed to new lows, the "smart money" is buying, and the selling pressure (as measured by volume) is weakening. This is often a leading indicator of a potential bottom or a significant upward reversal.

### 2. Bearish Divergence (A Leading Sell Signal)

* **Pattern:** The price makes a **new higher high**, but the **A/D Line fails to make a new high** and instead forms a lower high.
* **Interpretation:** This is a classic sign of **distribution**. It suggests that even as the price is pushed to new highs (often by public enthusiasm), the "smart money" is quietly selling their positions. The buying pressure (as measured by volume) is not strong enough to confirm the new price high. This is often a leading indicator of a potential top or a significant downward reversal.

### 3. Trend Confirmation

* If both the price and the A/D Line are making new highs together, it confirms the strength and health of the uptrend.
* If both are making new lows together, it confirms the strength of the downtrend.
* A lack of new highs or lows in the A/D line while the price continues to trend can be an early warning that the trend is losing its underlying volume support.
