mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-04 16:17:44 +00:00
refactor: Added selectable signal line type
This commit is contained in:
@@ -2,57 +2,58 @@
|
||||
|
||||
## 1. Summary (Introduction)
|
||||
|
||||
The `MACD_SuperSmoother_Pro` is a modern, high-performance variant of the classic MACD indicator. It replaces all three traditional Exponential Moving Averages (EMAs) with John Ehlers' highly responsive, low-lag SuperSmoother filters.
|
||||
The `MACD_SuperSmoother_Pro` is a modern, high-performance variant of the classic MACD indicator. It replaces the traditional Exponential Moving Averages (EMAs) of the MACD line with John Ehlers' highly responsive, low-lag **SuperSmoother filters**.
|
||||
|
||||
The result is a "pure" Ehlers-based system that provides a much smoother, more cyclical, and significantly faster representation of momentum compared to its conventional counterpart. By using SuperSmoothers for the fast line, slow line, and the signal line, the indicator minimizes the cumulative lag that is a common drawback of the standard MACD.
|
||||
The result is a MACD line that is smoother, more cyclical, and significantly faster than its conventional counterpart. This indicator then enhances this low-lag MACD line with a **fully customizable signal line**, allowing the user to choose from standard moving averages or another SuperSmoother for maximum flexibility.
|
||||
|
||||
This indicator calculates and displays all three core components of a MACD system:
|
||||
|
||||
* **MACD Line:** The difference between a fast and a slow SuperSmoother filter.
|
||||
* **Signal Line:** A SuperSmoother filter applied to the MACD Line.
|
||||
* **Signal Line:** A user-selectable moving average applied to the MACD Line.
|
||||
* **Histogram:** The difference between the MACD Line and the Signal Line.
|
||||
|
||||
## 2. Mathematical Foundations and Calculation Logic
|
||||
|
||||
The entire system is built using SuperSmoother filters, which are advanced two-pole Gaussian filters designed for optimal smoothing with minimal lag.
|
||||
The system is built by first creating a SuperSmoother-based MACD line, then applying a flexible signal line to it.
|
||||
|
||||
### Required Components
|
||||
|
||||
* **Fast Period (N)** and **Slow Period (M)** for the MACD Line.
|
||||
* **Signal Period (S)** for the Signal Line.
|
||||
* **Signal Period (S)** and **MA Type** for the Signal Line.
|
||||
* **Source Price (P)**.
|
||||
|
||||
### Calculation Steps (Algorithm)
|
||||
|
||||
1. **Calculate the Fast and Slow SuperSmoother Filters:** Two separate SuperSmoother filters are calculated on the source price `P`, one with a fast period and one with a slow period.
|
||||
1. **Calculate the Fast and Slow SuperSmoother Filters:** Two separate SuperSmoother filters are calculated on the source price `P`.
|
||||
* $\text{Fast Smoother}_t = \text{SuperSmoother}(P, N)_t$
|
||||
* $\text{Slow Smoother}_t = \text{SuperSmoother}(P, M)_t$
|
||||
|
||||
2. **Calculate the MACD Line:** The MACD Line is the difference between the two filters.
|
||||
* $\text{MACD Line}_t = \text{Fast Smoother}_t - \text{Slow Smoother}_t$
|
||||
|
||||
3. **Calculate the Signal Line:** A third SuperSmoother filter is applied directly to the `MACD Line` calculated in the previous step, using the signal period.
|
||||
* $\text{Signal Line}_t = \text{SuperSmoother}(\text{MACD Line}, S)_t$
|
||||
3. **Calculate the Signal Line:** A moving average of the user-selected type (`MA Type`) is applied directly to the `MACD Line` calculated in the previous step.
|
||||
* $\text{Signal Line}_t = \text{MA}(\text{MACD Line}, S, \text{MA Type})_t$
|
||||
|
||||
4. **Calculate the Histogram:** The final output is the difference between the MACD Line and the Signal Line.
|
||||
* $\text{Histogram}_t = \text{MACD Line}_t - \text{Signal Line}_t$
|
||||
|
||||
## 3. MQL5 Implementation Details
|
||||
|
||||
* **Modular and Composite Design:** The core logic is encapsulated in the `MACD_SuperSmoother_Calculator.mqh`. This calculator uses a composition-based design:
|
||||
* It contains **two instances** of our robust, state-managed `Ehlers_Smoother_Calculator` to generate the base MACD line from the source price.
|
||||
* For maximum stability, the **signal line's SuperSmoother filter is calculated manually** within the `Calculate` method, with its own dedicated state-management variables (`m_sig_f1`, `m_sig_f2`).
|
||||
* **Modular and Composite Design:** The `MACD_SuperSmoother_Calculator.mqh` uses a composition-based design: it **contains two instances** of our robust, state-managed `Ehlers_Smoother_Calculator` to generate the base MACD line.
|
||||
|
||||
* **Robust State Management:** All recursive calculations, both in the external `Ehlers_Smoother_Calculator` and for the internal signal line calculation, use persistent member variables to maintain their state between ticks. This is critical for the stability and accuracy of Ehlers' filters.
|
||||
* **Flexible Signal Line Calculation:** The calculator uses a `switch` block and a reusable `CalculateMA` helper function to apply the user's chosen smoothing method for the signal line. This includes a dedicated, state-managed calculation for the `SuperSmoother` option.
|
||||
|
||||
* **Heikin Ashi Integration:** A "Factory Method" (`CreateSmootherInstance`) is used to instantiate the correct type of smoother (`standard` or `_HA`), allowing the Heikin Ashi logic to be cleanly integrated without duplicating the main calculation chain.
|
||||
* **Robust State Management:** All recursive calculations use persistent member variables to maintain their state between ticks, which is critical for the stability and accuracy of Ehlers' filters.
|
||||
|
||||
* **Heikin Ashi Integration:** A "Factory Method" (`CreateSmootherInstance`) is used to instantiate the correct type of smoother (`standard` or `_HA`), allowing for clean Heikin Ashi integration.
|
||||
|
||||
## 4. Parameters
|
||||
|
||||
* **Fast Period (`InpFastPeriod`):** The period for the fast SuperSmoother filter. Default is `12`.
|
||||
* **Slow Period (`InpSlowPeriod`):** The period for the slow SuperSmoother filter. Default is `26`.
|
||||
* **Signal Period (`InpSignalPeriod`):** The period for the signal line's SuperSmoother filter. Default is `9`.
|
||||
* **Applied Price (`InpSourcePrice`):** The source price for the calculation (Standard or Heikin Ashi).
|
||||
* **Signal Period (`InpSignalPeriod`):** The period for the signal line's smoothing. Default is `9`.
|
||||
* **Signal MA Type (`InpSignalMAType`):** A dropdown menu to select the smoothing type for the signal line. Options include `SMA`, `EMA`, `SMMA`, `LWMA`, and `SuperSmoother`.
|
||||
|
||||
## 5. Usage and Interpretation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user