mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-06 17:17:45 +00:00
new files added
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
# Zero-Lag EMA Professional (ZLEMA)
|
||||
|
||||
## 1. Summary (Introduction)
|
||||
|
||||
The Zero-Lag Exponential Moving Average (ZLEMA), based on a concept developed by John Ehlers, is an enhanced version of the traditional Exponential Moving Average (EMA). Its primary goal is to **reduce or eliminate the inherent lag** associated with standard moving averages.
|
||||
|
||||
All moving averages lag behind the price because they are based on past data. The ZLEMA addresses this problem by adding a "momentum" or "error correction" term to the standard EMA calculation. This term essentially measures the lag of the EMA in the recent past and adds it back to the current value.
|
||||
|
||||
The result is a moving average that is **more responsive to recent price changes** and "hugs" the price more closely than a standard EMA of the same period, while still providing a good degree of smoothing. It is an excellent tool for traders who require more timely signals from their moving averages.
|
||||
|
||||
## 2. Mathematical Foundations and Calculation Logic
|
||||
|
||||
While Ehlers' original article describes a more complex, adaptive "Error Correcting" filter, the most widely adopted and robust implementation of the Zero-Lag EMA concept uses a "double EMA" technique to de-lag the average.
|
||||
|
||||
### Required Components
|
||||
|
||||
* **Period (N):** The lookback period for the underlying EMA calculations.
|
||||
* **Source Price (P):** The price series used for the calculation.
|
||||
|
||||
### Calculation Steps (Algorithm)
|
||||
|
||||
1. **Calculate the First EMA:** A standard `N`-period EMA is calculated on the source price.
|
||||
* `EMA1 = EMA(Price, N)`
|
||||
2. **Calculate the Second EMA:** A second `N`-period EMA is calculated, but this time its input is the result of the first EMA.
|
||||
* `EMA2 = EMA(EMA1, N)`
|
||||
3. **Identify the "Lag" or "Error":** The difference between the two EMAs represents the lag.
|
||||
* `Lag = EMA1 - EMA2`
|
||||
4. **Calculate the Final ZLEMA:** The calculated lag is added back to the first EMA to produce the final, de-lagged value.
|
||||
* `ZLEMA = EMA1 + Lag` (which simplifies to `2 * EMA1 - EMA2`)
|
||||
|
||||
## 3. MQL5 Implementation Details
|
||||
|
||||
* **Self-Contained Calculator (`ZeroLag_EMA_Calculator.mqh`):** The entire two-stage, recursive calculation is encapsulated within a dedicated, reusable calculator class.
|
||||
* **Heikin Ashi Integration:** An inherited `_HA` class allows the calculation to be performed seamlessly on smoothed Heikin Ashi data.
|
||||
* **Stability via Full Recalculation:** The calculation is doubly recursive. To ensure absolute stability and prevent desynchronization errors, the indicator employs a **full recalculation** on every `OnCalculate` call. The recursive state is managed internally within the calculation loop.
|
||||
* **Robust Initialization:** The internal EMAs are carefully initialized with a Simple Moving Average (SMA) to provide a stable starting point for the recursive calculations.
|
||||
|
||||
## 4. Parameters
|
||||
|
||||
* **Period (`InpPeriod`):** The lookback period (`N`) used for both underlying EMA calculations. This is the primary parameter for controlling the indicator's speed and smoothness.
|
||||
* A **shorter period** (e.g., 12) results in a faster, more responsive ZLEMA.
|
||||
* A **longer period** (e.g., 50) results in a slower, smoother ZLEMA.
|
||||
* **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.
|
||||
|
||||
## 5. Usage and Interpretation
|
||||
|
||||
The ZLEMA should be used in the same way as a traditional moving average, but with the understanding that its signals will be more timely.
|
||||
|
||||
* **Dynamic Support and Resistance:** The ZLEMA line acts as a dynamic level of support in an uptrend and resistance in a downtrend. Because it has less lag, it will often be tested sooner and more accurately than a standard EMA.
|
||||
* **Trend Filtering:** A longer-period ZLEMA (e.g., 50 or 100) can be used to define the overall market bias. Its reduced lag can provide an earlier warning of a potential trend change.
|
||||
* **Crossover Signals:**
|
||||
* **Price Crossover:** A crossover of the price and the ZLEMA line is a potential trade signal. These signals will occur earlier than with a standard EMA.
|
||||
* **Two-Line Crossover:** A system using a fast ZLEMA (e.g., 21-period) and a slow ZLEMA (e.g., 50-period) will generate crossover signals sooner than an equivalent EMA-based system, allowing for earlier entry into new trends.
|
||||
|
||||
**Caution:** The ZLEMA's increased responsiveness also means it can be more susceptible to "whipsaws" in choppy, sideways markets compared to a smoother, slower-moving average. It is most effective in clear, trending market conditions.
|
||||
Reference in New Issue
Block a user