diff --git a/Indicators/MyIndicators/McGinleyDynamic_Pro.md b/Indicators/MyIndicators/McGinleyDynamic_Pro.md new file mode 100644 index 0000000..b0f615b --- /dev/null +++ b/Indicators/MyIndicators/McGinleyDynamic_Pro.md @@ -0,0 +1,53 @@ +# McGinley Dynamic Professional + +## 1. Summary (Introduction) + +The McGinley Dynamic indicator, developed by John R. McGinley, is a more responsive and reliable alternative to traditional moving averages. Unlike averages with a fixed period, the McGinley Dynamic automatically adjusts its speed based on the speed of the market itself. + +Its primary purpose is to hug prices more closely, minimizing whipsaws. It speeds up in down markets to protect capital and slows down in up markets to let profits run. + +Our `McGinleyDynamic_Pro` implementation is a unified, professional version that allows the calculation to be based on either **standard** or **Heikin Ashi** price data, selectable from a single input parameter. + +## 2. Mathematical Foundations and Calculation Logic + +The core of the McGinley Dynamic is its unique, self-adjusting smoothing factor. The formula is recursive, with each new value depending on the previous one. + +### Required Components + +* **Length (N):** The base period for the indicator. +* **Source Price (P):** The price series used for the calculation. + +### Calculation Steps (Algorithm) + +1. **Initialization:** The first value of the McGinley Dynamic line is the first available source price. + $\text{MD}_0 = P_0$ + +2. **Recursive Calculation:** All subsequent values are calculated using the following formula: + $\text{MD}_i = \text{MD}_{i-1} + \frac{P_i - \text{MD}_{i-1}}{N \times (\frac{P_i}{\text{MD}_{i-1}})^4}$ + +The key component is the denominator, which contains the ratio $(\frac{P_i}{\text{MD}_{i-1}})$ that measures the speed of the market and adjusts the indicator's responsiveness. + +## 3. MQL5 Implementation Details + +Our MQL5 implementation follows a modern, object-oriented design to ensure stability, reusability, and maintainability. + +* **Modular Calculation Engine (`McGinleyDynamic_Calculator.mqh`):** + The entire calculation logic is encapsulated within a reusable include file. + * **`CMcGinleyDynamicCalculator`**: The base class that performs the full recursive calculation on a given source price. + * **`CMcGinleyDynamicCalculator_HA`**: A child class that inherits all the complex logic and only overrides the initial data preparation step to use smoothed Heikin Ashi prices as its input. This object-oriented approach eliminates code duplication. + +* **Stability via Full Recalculation:** We employ a "brute-force" full recalculation within `OnCalculate`. For a recursive indicator like the McGinley Dynamic, this is the most reliable method to prevent calculation errors. + +* **Robust Initialization and Defensive Coding:** The recursive calculation is carefully initialized with the first available price. The calculation loop includes explicit checks to prevent division by zero, enhancing the indicator's robustness. + +## 4. Parameters + +* **Length (`InpLength`):** The base period for the indicator. McGinley suggested this value should be approximately 60% of the period of a corresponding SMA. Default is `14`. +* **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 + +* **Trend Identification:** The McGinley Dynamic is primarily used as a dynamic trend line. When the price is above the line, the trend is considered bullish. When the price is below the line, the trend is considered bearish. +* **Dynamic Support and Resistance:** The line itself can act as a more reliable level of dynamic support or resistance compared to traditional moving averages, as it reacts more quickly to changes in market speed. +* **Crossovers:** Crossovers of the price and the McGinley Dynamic line can be used as trade signals. +* **Caution:** While it reduces whipsaws, it is still a lagging indicator (though less so than others) and should be used in conjunction with other forms of analysis for confirmation.