mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-11-02 11:16:15 +00:00
new files added
This commit is contained in:
@@ -0,0 +1,207 @@
|
||||
# Gerald Appel's Moving Average Convergence Divergence (MACD) Pro (v5.00)
|
||||
|
||||
Quantitative Universal Multi-Algorithm MACD & Volume-Weighted Momentum Suite
|
||||
|
||||
---
|
||||
|
||||
## 1. Summary (Introduction)
|
||||
|
||||
**MACD Pro** is an institutional-grade trend-following momentum oscillator developed by technical analyst Gerald Appel. It evaluates the relationship between two moving averages of price to identify trend direction, momentum acceleration, and structural inflection points.
|
||||
|
||||
While standard platform MACDs restrict calculations to fixed exponential averages on raw close prices, **MACD Pro provides universal algorithmic modularity**:
|
||||
|
||||
* **Universal Algorithm Selection:** Fast, Slow, and Signal smoothing lines can independently utilize all eight moving average models (SMA, EMA, SMMA, LWMA, TMA, DEMA, TEMA, and Volume-Weighted VWMA).
|
||||
* **Volume-Weighted Momentum (VWMA-MACD):** Incorporates real trade volume (`VOLUME_REAL`) or tick volume (`VOLUME_TICK`) into moving average calculations, filtering out low-liquidity false breakouts.
|
||||
* **Tri-Plot Visual Suite:** Displays the MACD Line, Signal Line, and difference Histogram together in a unified subwindow.
|
||||
* **Unified 2026 MTF Framework:** Higher-timeframe MACD curves (e.g., H1 or H4) map onto lower-timeframe execution charts (M1, M5, M15) with flat, non-warping steps via `DataSync_Tools.mqh`.
|
||||
* **Synthetic Heikin Ashi Support:** Fully compatible with filtered Heikin Ashi price series via `CMACDCalculator_HA` composition.
|
||||
|
||||
```text
|
||||
|
||||
┌────────────────────────────────────────────────────────────────────────┐
|
||||
│ MACD TRI-PLOT ARCHITECTURE │
|
||||
├──────────────────────┬────────────────────────┬────────────────────────┤
|
||||
│ Output Plot │ Color Code │ Core Role │
|
||||
├──────────────────────┼────────────────────────┼────────────────────────┤
|
||||
│ Histogram Difference │ clrSilver (Width:1) │ Momentum Acceleration │
|
||||
│ MACD Line │ clrDodgerBlue (Width:2)│ Fast - Slow Spread │
|
||||
│ Signal Trigger Line │ clrOrangeRed (Width:1) │ Smoothed Trigger Line │
|
||||
└──────────────────────┴────────────────────────┴────────────────────────┘
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. Mathematical Foundations & Convergence Mechanics
|
||||
|
||||
```text
|
||||
|
||||
FAST MOVING AVERAGE: MA( Price, Period = P_Fast )
|
||||
SLOW MOVING AVERAGE: MA( Price, Period = P_Slow )
|
||||
│
|
||||
▼
|
||||
MACD Line = Fast MA - Slow MA
|
||||
│
|
||||
▼
|
||||
Signal Line = MA( MACD Line, Period = P_Signal )
|
||||
│
|
||||
▼
|
||||
Histogram = MACD Line - Signal Line
|
||||
|
||||
```
|
||||
|
||||
### 2.1. Fast & Slow Moving Average Calculation
|
||||
|
||||
Given input price series $P_t$:
|
||||
$$\text{Fast MA}_t = \mathcal{MA}\left( P, \text{Period} = P_{\text{Fast}}, \text{Type} = \text{InpSourceMAType} \right)$$
|
||||
$$\text{Slow MA}_t = \mathcal{MA}\left( P, \text{Period} = P_{\text{Slow}}, \text{Type} = \text{InpSourceMAType} \right)$$
|
||||
*where standard parameters are $P_{\text{Fast}} = 12$ and $P_{\text{Slow}} = 26$.*
|
||||
|
||||
---
|
||||
|
||||
### 2.2. The MACD Line Formulation
|
||||
|
||||
The MACD Line measures the absolute spread between the short-term and long-term moving averages:
|
||||
$$\text{MACD}_t = \text{Fast MA}_t - \text{Slow MA}_t$$
|
||||
|
||||
---
|
||||
|
||||
### 2.3. The Signal Line Smoothing
|
||||
|
||||
The Signal Line is generated by smoothing the MACD Line over period $P_{\text{Signal}} = \text{InpSignalPeriod}$ (default: $9$):
|
||||
$$\text{Signal}_t = \mathcal{MA}\left( \text{MACD}, \text{Period} = P_{\text{Signal}}, \text{Type} = \text{InpSignalMAType} \right)$$
|
||||
|
||||
---
|
||||
|
||||
### 2.4. The MACD Difference Histogram
|
||||
|
||||
The histogram reflects the instantaneous rate of convergence or divergence between the MACD Line and the Signal Line:
|
||||
$$\text{Histogram}_t = \text{MACD}_t - \text{Signal}_t$$
|
||||
|
||||
---
|
||||
|
||||
### 2.5. Volume-Weighted MACD Model (VWMA-MACD)
|
||||
|
||||
When `InpSourceMAType = VWMA`, moving averages weight prices directly proportional to transacted trade volume ($V_k$):
|
||||
$$\text{Fast VWMA}_t = \frac{\sum_{k=0}^{P_{\text{Fast}}-1} P_{t-k} \cdot V_{t-k}}{\sum_{k=0}^{P_{\text{Fast}}-1} V_{t-k}}, \quad\quad \text{Slow VWMA}_t = \frac{\sum_{k=0}^{P_{\text{Slow}}-1} P_{t-k} \cdot V_{t-k}}{\sum_{k=0}^{P_{\text{Slow}}-1} V_{t-k}}$$
|
||||
$$\text{VWMA-MACD}_t = \text{Fast VWMA}_t - \text{Slow VWMA}_t$$
|
||||
|
||||
---
|
||||
|
||||
## 3. MQL5 Architecture & Engineering Standards
|
||||
|
||||
```text
|
||||
|
||||
┌────────────────────────────────────────────────────────┐
|
||||
│ MovingAverage_Engine.mqh │
|
||||
│ (Core Universal Math: 8 MA Types & VWMA) │
|
||||
└──────────────────────────┬─────────────────────────────┘
|
||||
│ Powers Fast, Slow & Signal MAs
|
||||
▼
|
||||
┌────────────────────────────────────────────────────────┐
|
||||
│ MACD_Calculator.mqh │
|
||||
│ (Fast/Slow Convergence, Signal & Histogram Engine) │
|
||||
├──────────────────────────┬─────────────────────────────┤
|
||||
│ Volume Routing Layer │ Composition Engine │
|
||||
│ • Real Volume Support │ • CMACDCalculator_HA │
|
||||
│ • Tick Volume Fallback │ • Leak-Free Destructors │
|
||||
└──────────────────────────┴─────────────────────────────┘
|
||||
│ Outputs MACD, Signal, Histogram
|
||||
▼
|
||||
┌────────────────────────────────────────────────────────┐
|
||||
│ MACD_Pro.mq5 │
|
||||
│ (Unified Wrapper: Native Timeframe & MTF Engine) │
|
||||
├──────────────────────────┬─────────────────────────────┤
|
||||
│ Direct Mode (O(1)) │ Synchronized MTF Pipeline │
|
||||
│ • Current Timeframe │ • DataSync_Tools Daemon │
|
||||
│ • 3 Output Plots │ • Staircase Flat-Force │
|
||||
└──────────────────────────┴─────────────────────────────┘
|
||||
|
||||
```
|
||||
|
||||
1. **3-Engine Composition Architecture:** `CMACDCalculator` coordinates three internal `CMovingAverageCalculator` engines (`m_fast_ma_engine`, `m_slow_ma_engine`, `m_signal_ma_engine`) with zero heap memory leaks.
|
||||
2. **Full VWMA Volume Routing:** Volume arrays (`h_vol[]` in MTF and `volume[]` in Native) are routed into Fast, Slow, and Signal smoothing pipelines.
|
||||
3. **2026 MTF Framework with Staircase Solution:**
|
||||
* Asynchronous 1-second timer daemon (`OnTimerUpdate`) ensures higher-timeframe data synchronization without UI lag.
|
||||
* Dynamic staircase anchor (`first_bar_of_forming_htf`) synchronizes all lower-timeframe sub-bars belonging to the active higher-timeframe candle.
|
||||
|
||||
---
|
||||
|
||||
## 4. Parameters Reference
|
||||
|
||||
### Timeframe Settings
|
||||
|
||||
* `InpTimeframe` (*default: `PERIOD_CURRENT`*): Calculation timeframe. When set to `PERIOD_CURRENT`, it operates in native zero-lag mode. When set to a higher timeframe (e.g., `PERIOD_H1`, `PERIOD_D1`), it activates the synchronized MTF engine.
|
||||
|
||||
### MACD Core Settings
|
||||
|
||||
* `InpFastPeriod` (*default: `12`*): Lookback period ($P_{\text{Fast}}$) for the fast moving average.
|
||||
* `InpSlowPeriod` (*default: `26`*): Lookback period ($P_{\text{Slow}}$) for the slow moving average.
|
||||
* `InpSignalPeriod` (*default: `9`*): Lookback period ($P_{\text{Signal}}$) for the signal line.
|
||||
* `InpSourceMAType` (*default: `EMA`*): Smoothing algorithm for Fast and Slow lines (`SMA`, `EMA`, `SMMA`, `LWMA`, `TMA`, `DEMA`, `TEMA`, `VWMA`).
|
||||
* `InpSignalMAType` (*default: `EMA`*): Smoothing algorithm for the Signal line.
|
||||
* `InpSourcePrice` (*default: `PRICE_CLOSE_STD`*): Price series source (Supports all 7 Standard and 7 Heikin Ashi modes).
|
||||
|
||||
### Visual Settings - MACD Line
|
||||
|
||||
* `InpColorMACD` (*default: `clrDodgerBlue`*): MACD Line color (Width: 2, Solid).
|
||||
* `InpStyleMACD` (*default: `STYLE_SOLID`*): Line style of the MACD Line.
|
||||
* `InpWidthMACD` (*default: `2`*): Line thickness.
|
||||
|
||||
### Visual Settings - Signal Line
|
||||
|
||||
* `InpColorSignal` (*default: `clrOrangeRed`*): Signal Line color (Width: 1, Solid).
|
||||
* `InpStyleSignal` (*default: `STYLE_SOLID`*): Line style of the Signal Line.
|
||||
* `InpWidthSignal` (*default: `1`*): Line thickness.
|
||||
|
||||
### Visual Settings - Histogram
|
||||
|
||||
* `InpColorHist` (*default: `clrSilver`*): Histogram difference color (Width: 1, Solid).
|
||||
* `InpStyleHist` (*default: `STYLE_SOLID`*): Histogram bar style.
|
||||
* `InpWidthHist` (*default: `1`*): Histogram bar width.
|
||||
|
||||
---
|
||||
|
||||
## 5. Quantitative Trading Playbooks
|
||||
|
||||
```text
|
||||
|
||||
┌────────────────────────────────────────────────────────────────────────┐
|
||||
│ MACD TRADING PLAYBOOKS │
|
||||
├────────────────────────────────────────────────────────────────────────┤
|
||||
│ 1. Centerline Regime Cross: MACD Line > 0 = Bullish Macro Momentum. │
|
||||
│ MACD Line < 0 = Bearish Macro Momentum. │
|
||||
│ 2. Signal Line Crossover: MACD Line crosses Signal Line in direction │
|
||||
│ of the 0.0 baseline bias. │
|
||||
│ 3. Histogram Acceleration: Expanding histogram bars confirm impulse │
|
||||
│ momentum; contracting bars warn exhaustion.│
|
||||
└────────────────────────────────────────────────────────────────────────┘
|
||||
|
||||
```
|
||||
|
||||
### 5.1. The 0.0 Centerline Macro Regime Filter
|
||||
|
||||
* **Bullish Regime:** When `MACD Line > 0.0`, the Fast MA is trading above the Slow MA $\rightarrow$ Macro market markup is active. Focus on long continuation setups.
|
||||
* **Bearish Regime:** When `MACD Line < 0.0`, the Fast MA is trading below the Slow MA $\rightarrow$ Macro markdown is active. Focus on short setups.
|
||||
|
||||
### 5.2. Signal Line Crossovers (MACD / Signal)
|
||||
|
||||
* **Bullish Entry Trigger:** `MACD Line > 0.0` AND `MACD Line` crosses **above Signal Line** $\rightarrow$ High-probability long trend entry.
|
||||
* **Bearish Entry Trigger:** `MACD Line < 0.0` AND `MACD Line` crosses **below Signal Line** $\rightarrow$ High-probability short trend entry.
|
||||
|
||||
### 5.3. Multi-Timeframe Macro Confluence
|
||||
|
||||
* Attach an **H1-calculated MACD Pro** onto an **M5 execution chart**.
|
||||
* **Rule:** Only take M5 long breakout/pullback entries when **H1 MACD Line is above 0.0 AND above its H1 Signal Line**. This ensures that intraday execution aligns with macro institutional volume momentum.
|
||||
|
||||
---
|
||||
|
||||
## 6. Indicator Buffer Map (For Developers & EA Integration)
|
||||
|
||||
| Buffer Index | Name | Type | Description |
|
||||
| :---: | :---: | :--- | :--- |
|
||||
| **0** | `BufferMACD_Histogram` | `INDICATOR_DATA` | Histogram Difference Plot ($\text{MACD} - \text{Signal}$) |
|
||||
| **1** | `BufferMACDLine` | `INDICATOR_DATA` | Main MACD Line ($\text{Fast MA} - \text{Slow MA}$) |
|
||||
| **2** | `BufferSignalLine` | `INDICATOR_DATA` | Smoothed Signal Line ($\mathcal{MA}(\text{MACD})$) |
|
||||
|
||||
*All buffers strictly maintain non-series chronological order (`ArraySetAsSeries = false`), ensuring instant compatibility with Expert Advisors and scanner dashboards via `iCustom()`.*
|
||||
Reference in New Issue
Block a user