Fixed-Width Fractional Differencing (FFD)

Fixed-Width Fractional Differencing (FFD)
Download ALL MT5 indicators (5649)
YouTube Video Thumbnail

Similar MetaTrader Tools

Fixed-Width Fractional Differencing (FFD)

Info

The Fixed-Width Fractional Differencing (FFD) is a Indicator for MetaTrader 5 that raw forex and futures prices exhibit non-stationarity, which poses challenges for standard regression and classification models due to look-ahead bias and spurious correlations. Integer differencing, a common solution, eliminates non-stationarity but sacrifices price memory, hindering predictive model performance.

Usage

This tool is typically used for enhancing chart analysis and decision making.

Platform

This Indicator works exclusively on MetaTrader 5 (both build 600+ and newer versions).

Setup

Place the downloaded file in MQL5/Indicators folder via File ? Open Data Folder in MetaTrader 5.


How to Install and Use Fixed-Width Fractional Differencing (FFD)

1. Installation: Place your file in the MQL/Indicators folder via "Open Data Folder" and restart your terminal.

2. Loading: Find the indicator in the Navigator, drag it onto your chart, and configure the input parameters in the popup window.

3. Customization: Press Ctrl+I to open the indicator list, select your tool, and click "Properties" to change colors, levels, or visual styles.

4. Updating: Replace the old file in the Indicators folder with the new version and restart the platform to apply changes.

Frequently Asked Questions

Q: Why is my indicator not showing? A: Verify the file is in the MQL/Indicators folder, or try right-clicking the "Indicators" tree in the Navigator and clicking "Refresh."

Q: Do custom indicators slow down the platform? A: Too many complex indicators can impact performance; remove unused ones via the "Indicator List" (Ctrl+I).

Q: Can I use MT4 indicators on MT5? A: No, MQL4 and MQL5 are distinct languages; ensure the indicator is compiled specifically for your platform version.

What this tool does

Raw forex and futures prices exhibit non-stationarity, which poses challenges for standard regression and classification models due to look-ahead bias and spurious correlations.

Typical Use Case

This Indicator excels in automated trading and technical analysis on MetaTrader 5.

Compatible Platform & Setup

This Indicator works on MetaTrader 5. Place the file in the MQL5/Indicators folder and restart the terminal.

Description & Settings

Related: Fractional Bands - another powerful indicator for MetaTrader 5 traders.

Raw forex and futures prices exhibit non-stationarity, which poses challenges for standard regression and classification models due to look-ahead bias and spurious correlations. Integer differencing, a common solution, eliminates non-stationarity but sacrifices price memory, hindering predictive model performance.

Also recommended: Fractional Bands HT F - similar indicator with strong performance on MetaTrader 5.


Fixed-width fractional differencing (FFD), introduced in Chapter 5 of Advances in Financial Machine Learning (2026), addresses this dilemma by differencing at a non-integer order d ∈ (0, 1), ensuring stationarity while retaining maximum memory.

This MQL5 implementation offers a production-grade solution for FFD.

Illustration: Two-panel comparison of non-stationary raw price (a) and stationary FFD series (b) with the lookback window highlighted.

Components

FFDEngine.mqh
- Header-only library featuring the CFFDEngine class. Includes Init(), Compute() for single bar processing, and ComputeBuffer() for full indicator buffer calculation with prev_calculated optimization. No dynamic memory allocation post-OnInit().

FFD.mq5
- Custom indicator built on CFFDEngine. Displays the FFD series in a separate chart window, supporting all ENUM_APPLIED_PRICE values.

Algorithm Functionality
The weight vector is defined by the recurrence (AFML eq. 5.4):
w[0] = 1 w[k] = -w[k-1] * (d - k + 1) / k, k = 1, 2, ...
Iteration ceases when |w[k]| < threshold. The vector is reversed, assigning the smallest weight to the oldest price in the lookback window and 1.0 to the newest price. The FFD value at bar i is the dot product of the reversed weight vector with the log-price window [i−width, …, i].
For d = 0.4 and threshold = 1e-5, the window width is 1 457 bars. With threshold = 1e-3, it reduces to 54 bars. The threshold balances stationarity and memory retention, with smaller values preserving more memory but requiring a wider lookback.

Installation
Copy FFDEngine.mqh to MQL5\Include\ or the specified subfolder during CodeBase download.
Place FFD.mq5 in MQL5\Indicators\Downloads\ (automatic placement on CodeBase download).
Compile both files in MetaEditor, ensuring the indicator compiles without warnings under #property strict.
Attach FFD to any chart; the indicator window will display below the main chart after the lookback window (width + 1 bars) is filled.

Integrating CFFDEngine into Your EA or Indicator
FFDEngine.mqh is header-only. Include it and call Init() once in OnInit():

Cross-Validation with Python
FFDValidation.mq5 (in the article download) exports FFD values to CSV. The Python script ffd_cross_validate.py recalculates these values using the afml library and performs bar-by-bar comparison. On 5 000 bars of EURUSD H1 with d = 0.4 and threshold = 1e-5, the maximum absolute difference is less than 1e-12.

Performance Notes
Weight vector allocation: once in OnInit(). No allocation on the tick path.
Per-bar computation: O(width) dot product. Modern hardware completes a 1 457-element dot product in under 50 μs.
ComputeBuffer() leverages prev_calculated to recompute only the current incomplete bar on each tick.

References and Companion Resources
Advances in Financial Machine Learning (2026), Chapter 5 (Fractional Differentiation), pp. 76–95, Wiley.
Full theory, Python implementation, and ADF-based parameter search: Patrick M. Njoroge.
Companion validation tools: FFDValidation.mq5 and ffd_cross_validate.py, included in the article download package.

You may also like: Six Soldiers - excellent alternative for indicator users on MetaTrader 5.


Leave your opinion, ask a question, share some knowledge

Limitations & Risk Warning

  • This tool is provided for educational and testing purposes only.
  • Past performance does not guarantee future results.
  • Trading involves substantial risk of loss. Use on a demo account first.
  • Results may vary depending on market conditions, broker, and settings.
  • We recommend thorough backtesting and forward testing before using with real funds.
RobotFX does not own any of the code provided on this platform. All tools are freely available on the internet; we simply index and re-offer them for download. We are not responsible for any financial losses that may occur. Trading responsibilities rely solely on the traders downloading and using the displayed Expert Advisors, indicators, and scripts. These tools are provided for educational purposes only and may require modification or optimization to align with a trader's specific strategy or needs.
© ROBOTFX - Best MetaTrader Expert Advisors & Indicators