mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-02 15:17:43 +00:00
refactor: Added DEMA and TEMA types
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
## 1. Summary (Introduction)
|
||||
|
||||
The `MovingAverage_Pro` is a universal, "all-in-one" moving average indicator designed for maximum flexibility and efficiency. It consolidates the four most fundamental moving average types into a single, powerful tool, allowing the user to switch between them with a simple dropdown menu.
|
||||
The `MovingAverage_Pro` is a universal, "all-in-one" moving average indicator designed for maximum flexibility and efficiency. It consolidates **seven** fundamental and advanced moving average types into a single, powerful tool, allowing the user to switch between them with a simple dropdown menu.
|
||||
|
||||
The available moving average types are:
|
||||
|
||||
@@ -10,8 +10,11 @@ The available moving average types are:
|
||||
* **EMA** (Exponential Moving Average)
|
||||
* **SMMA** (Smoothed Moving Average)
|
||||
* **LWMA** (Linear Weighted Moving Average)
|
||||
* **TMA** (Triangular Moving Average)
|
||||
* **DEMA** (Double Exponential Moving Average)
|
||||
* **TEMA** (Triple Exponential Moving Average)
|
||||
|
||||
As part of our professional indicator suite, it fully supports calculations based on either **standard** or **Heikin Ashi** price data, providing a consistent and powerful tool for any analysis style.
|
||||
As part of our professional indicator suite, it fully supports calculations on either **standard** or **Heikin Ashi** price data, providing a consistent and powerful tool for any analysis style.
|
||||
|
||||
## 2. Mathematical Foundations and Calculation Logic
|
||||
|
||||
@@ -58,25 +61,48 @@ $\text{LWMA}_t = \frac{\sum_{i=0}^{N-1} P_{t-i} \times (N-i)}{\sum_{j=1}^{N} j}$
|
||||
|
||||
Where the denominator is the sum of the weights (e.g., for a 3-period LWMA, the weights are 3, 2, 1, and the sum is 6).
|
||||
|
||||
### TMA (Triangular Moving Average)
|
||||
|
||||
The TMA is a double-smoothed moving average that gives the most weight to the data in the middle of its lookback period. It is extremely smooth and is best used as a long-term trendline or cyclical centerline, not for fast signals. It is calculated by taking an SMA of an SMA.
|
||||
|
||||
1. $\text{SMA}_{1_t} = \text{SMA}(P, \text{Ceiling}(\frac{N + 1}{2}))_t$
|
||||
2. $\text{TMA}_t = \text{SMA}(\text{SMA}_1, \text{Floor}(\frac{N + 1}{2}))_t$
|
||||
|
||||
### DEMA (Double Exponential Moving Average)
|
||||
|
||||
Developed by Patrick Mulloy, the DEMA is not a simple double-smoothed EMA. It is a lag-reduction technique that combines a single EMA and a double EMA to create a more responsive moving average.
|
||||
|
||||
1. $\text{EMA}_{1_t} = \text{EMA}(P, N)_t$
|
||||
2. $\text{EMA}_{2_t} = \text{EMA}(\text{EMA}_1, N)_t$
|
||||
3. $\text{DEMA}_t = (2 \times \text{EMA}_{1_t}) - \text{EMA}_{2_t}$
|
||||
|
||||
### TEMA (Triple Exponential Moving Average)
|
||||
|
||||
Also developed by Patrick Mulloy, the TEMA is an even more advanced lag-reduction technique that uses a triple-smoothing process to create an extremely responsive moving average that stays very close to the price.
|
||||
|
||||
1. $\text{EMA}_{1_t} = \text{EMA}(P, N)_t$
|
||||
2. $\text{EMA}_{2_t} = \text{EMA}(\text{EMA}_1, N)_t$
|
||||
3. $\text{EMA}_{3_t} = \text{EMA}(\text{EMA}_2, N)_t$
|
||||
4. $\text{TEMA}_t = (3 \times \text{EMA}_{1_t}) - (3 \times \text{EMA}_{2_t}) + \text{EMA}_{3_t}$
|
||||
|
||||
## 3. MQL5 Implementation Details
|
||||
|
||||
This indicator is a prime example of our modular and efficient design philosophy.
|
||||
|
||||
* **Universal Calculation Engine (`MovingAverage_Engine.mqh`):**
|
||||
The entire calculation logic for all four MA types is encapsulated within a single, reusable engine file. This centralized approach eliminates code duplication, simplifies maintenance, and ensures mathematical consistency across our entire indicator suite.
|
||||
The entire calculation logic for all **seven** MA types is encapsulated within a single, reusable engine file. This centralized approach eliminates code duplication and simplifies maintenance.
|
||||
|
||||
* **User-Selectable Type via Enum:** The indicator uses an `input ENUM_MA_TYPE` parameter, which creates a user-friendly dropdown menu in the settings window. The user's selection is passed directly to the universal engine, which then performs the correct calculation.
|
||||
* **Efficient EMA Calculation:** The engine uses a dedicated `CalculateEMA` helper function. This function is called recursively to efficiently build the DEMA and TEMA without rewriting the core EMA logic.
|
||||
|
||||
* **Object-Oriented Design (Inheritance):**
|
||||
A `CMovingAverageCalculator` base class and a `CMovingAverageCalculator_HA` derived class are used to cleanly separate the logic for standard and Heikin Ashi price sources. The child class only overrides the data preparation method, inheriting the entire calculation logic.
|
||||
* **User-Selectable Type via Enum:** The indicator uses an `input ENUM_MA_TYPE` parameter, which creates a user-friendly dropdown menu in the settings window. The user's selection is passed directly to the universal engine.
|
||||
|
||||
* **Dynamic Naming:** The indicator's name on the chart and in the Data Window automatically updates to reflect the user's current selections (e.g., "EMA HA(50)", "SMA(200)").
|
||||
* **Object-Oriented Design (Inheritance):** A `CMovingAverageCalculator` base class and a `CMovingAverageCalculator_HA` derived class are used to cleanly separate the logic for standard and Heikin Ashi price sources.
|
||||
|
||||
* **Dynamic Naming:** The indicator's name on the chart automatically updates to reflect the user's current selections (e.g., "DEMA HA(50)", "TMA(100)").
|
||||
|
||||
## 4. Parameters
|
||||
|
||||
* **Period (`InpPeriod`):** The lookback period for the moving average calculation.
|
||||
* **MA Type (`InpMAType`):** A dropdown menu to select the desired moving average type (SMA, EMA, SMMA, LWMA).
|
||||
* **Applied Price (`InpSourcePrice`):** The source price for the calculation. This unified dropdown menu allows you to select from all standard and Heikin Ashi price types.
|
||||
* **MA Type (`InpMAType`):** A dropdown menu to select the desired moving average type (SMA, EMA, SMMA, LWMA, TMA, DEMA, TEMA).
|
||||
* **Applied Price (`InpSourcePrice`):** The source price for the calculation.
|
||||
|
||||
## 5. Usage and Interpretation
|
||||
|
||||
|
||||
Reference in New Issue
Block a user