128 lines
5.2 KiB
Markdown
128 lines
5.2 KiB
Markdown
# Article-22015-Fixed-Width-Fractional-Differentiation-MQL5
|
|
|
|
This repository is an article-derived reference project based on the original MQL5 article. It does not claim to reproduce the full original source code unless files are explicitly attached.
|
|
|
|
## Overview
|
|
|
|
This project documents an MQL5 implementation of fixed-width fractional differentiation (FFD) for live MetaTrader 5 data feeds. The article presents a reusable `CFFDEngine` class for weight generation and dot-product computation, a custom indicator wrapper, and a validation workflow against a Python reference pipeline.
|
|
|
|
The implementation focus is practical deployment: precomputed weights, bounded lookback, no per-tick allocation, and efficient `prev_calculated` handling for indicator execution.
|
|
|
|
## Original Article
|
|
|
|
- **Article ID:** 22015
|
|
- **Title:** Fixed-Width Fractional Differentiation in MQL5
|
|
- **Author:** Patrick Murimi Njoroge
|
|
- **Publication date:** 2026.05.06
|
|
- **Category:** Python / Scripts / Indicators
|
|
- **URL:** https://www.mql5.com/en/articles/22015
|
|
|
|
## Repository Purpose
|
|
|
|
This repository serves as a reference/reconstruction project for the article's MQL5 FFD engine and surrounding examples.
|
|
|
|
Its purpose is to preserve the article-described architecture and code structure for:
|
|
|
|
- production-style FFD computation in MQL5
|
|
- indicator-based visualization
|
|
- EA-side integration
|
|
- numerical validation against a Python implementation
|
|
|
|
## Key Concepts
|
|
|
|
- Fixed-width fractional differentiation (FFD)
|
|
- Threshold-driven weight truncation
|
|
- Header-only MQL5 engine design
|
|
- Dot-product computation over bounded windows
|
|
- `prev_calculated` optimization in custom indicators
|
|
- Safe logarithmic transform with lower clipping
|
|
- EA integration via `iCustom` or direct embedding
|
|
- Cross-validation against Python / AFML workflow
|
|
|
|
## Algorithm / Architecture Summary
|
|
|
|
The article describes an engine-centered design:
|
|
|
|
1. **Initialization**
|
|
- Validate `d` and threshold parameters.
|
|
- Build the FFD weights using the recurrence
|
|
`w_k = -w_{k-1} * (d - k + 1) / k`
|
|
- Stop when `abs(w_k)` falls below the threshold.
|
|
- Reverse the weights so the oldest observation aligns with the oldest lag.
|
|
|
|
2. **Single-bar computation**
|
|
- Use the last `width + 1` prices.
|
|
- Optionally apply `ln(max(price, 1e-8))`.
|
|
- Compute a direct dot product between the weight vector and the selected window.
|
|
|
|
3. **Indicator mode**
|
|
- Fill an output buffer for chart display.
|
|
- Use `prev_calculated` to avoid full recomputation on every tick.
|
|
- Mark insufficient-history bars as `EMPTY_VALUE`.
|
|
|
|
4. **EA integration**
|
|
- Either consume the indicator via `iCustom`/`CopyBuffer`
|
|
- Or embed the engine directly and fetch the minimal required history via `CopyClose`
|
|
|
|
5. **Validation**
|
|
- Export MQL5 results to CSV.
|
|
- Recompute equivalent FFD values in Python.
|
|
- Compare maximum absolute difference, targeting sub-`1e-12` discrepancy.
|
|
|
|
## Mentioned or Attached Files
|
|
|
|
### Explicitly attached files
|
|
|
|
- **FFDEngine.mqh** — header-only `CFFDEngine` implementation for weight generation and FFD computation
|
|
- **FFD.mq5** — custom indicator wrapper for plotting the FFD series
|
|
- **FFDValidation.mq5** — MQL5 script for exporting validation data to CSV
|
|
- **ffd_cross_validate.py** — Python script for cross-checking MQL5 output against Python FFD calculations
|
|
|
|
### Files mentioned in the article text
|
|
|
|
- No additional source files were identified beyond the attached files listed by the article.
|
|
|
|
## Statistics
|
|
|
|
- **Core engine component:** 1 header-only class (`CFFDEngine`)
|
|
- **Primary deployment modes described:** 3
|
|
- custom indicator
|
|
- direct EA embedding
|
|
- multi-feature multi-engine usage
|
|
- **Typical width examples:**
|
|
- `d = 0.4`, `τ = 1e-5` → width ≈ 1457 bars
|
|
- `d = 0.4`, `τ = 1e-4` → width ≈ 281 bars
|
|
- **Performance ranges mentioned:**
|
|
- width range: 200–4000 bars
|
|
- compute time per bar: `< 1 ms`
|
|
- memory per engine: `< 40 KB`
|
|
- **Validation tolerance target:** max absolute difference `< 1e-12`
|
|
|
|
## Tags
|
|
|
|
`mql5`, `fractional-differentiation`, `ffd`, `quant`, `timeseries`, `custom-indicator`, `expert-advisor`, `python-validation`, `metaTrader5`
|
|
|
|
## Difficulty
|
|
|
|
**Intermediate to Advanced**
|
|
|
|
Requires familiarity with:
|
|
|
|
- MQL5 indicators and EAs
|
|
- time-series preprocessing
|
|
- numerical methods
|
|
- MetaTrader buffer and history APIs
|
|
- validation of cross-language implementations
|
|
|
|
## Limitations
|
|
|
|
- The repository is article-derived; full independently verified source packaging is not available unless the attached files are actually present in the processed repository input.
|
|
- Publication date and category were not available in the provided article extract.
|
|
- The README reflects the article narrative and code excerpts; it does not claim additional implementation details beyond what was explicitly shown.
|
|
- No build or installation workflow is documented here beyond the file placement conventions described in the article.
|
|
- If the actual repository does not contain the attached files, then this project should be treated as a reconstruction/reference only.
|
|
|
|
## Reference
|
|
|
|
- Patrick M. Njoroge, **[MQL5 Article 22015](https://www.mql5.com/en/articles/22015)**
|
|
- Related prior article mentioned: **[Part 1](https://www.mql5.com/en/articles/22014)** on theory and Python implementation of fractional differentiation
|