Symbolic Fourier Approximation in MQL5: a Fourier front end with MCB binning for historical analog search, measured head to head against SAX on identical windows.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
ayantrader ec67101c7e Add PAA-MCB control, paired standard errors and pinned data to SFACompare
SFACompare now runs a third coding (PAA cells with learned per-position
bins) to separate the bin-table and front-end effects, averages recall over
120 queries spread across the measured half, excludes windows overlapping the
query from the symbolic ranking, and reports each recall gap with its paired
standard error plus letter entropy. InpEndTime and InpSplit pin the data and
the fit/measure split so the article's numbers reproduce. README updated with
the findings.
2026-09-29 20:15:24 +05:00
Include Add PAA-MCB control, paired standard errors and pinned data to SFACompare 2026-09-29 20:15:24 +05:00
Indicators/SFA initial commit 2026-08-11 12:37:59 +00:00
Scripts/SFA Add PAA-MCB control, paired standard errors and pinned data to SFACompare 2026-09-29 20:15:24 +05:00
README.md Add PAA-MCB control, paired standard errors and pinned data to SFACompare 2026-09-29 20:15:24 +05:00

SFA

Symbolic Fourier Approximation in MQL5, and a direct comparison against SAX on identical windows.

Companion code for the MQL5 article: https://www.mql5.com/en/articles/24006

What it does

SAX spends its bits describing where a window sits in time. SFA spends them describing its shape: the window goes through a Fourier transform, the low coefficients are kept, and those are binned into letters.

The bins are not fixed. Multiple Coefficient Binning learns them from the data, so each coefficient gets breakpoints matched to its own distribution rather than to an assumed normal.

The lower bound is where this gets useful and where it is easy to get wrong. SFA admits a distance bound that lets the search skip candidates safely, and the article works through the factor of two that the bound carries, since getting it wrong either breaks correctness or throws away the speed.

SFACompare.mq5 runs SAX and SFA over the same windows so the comparison is like for like rather than two tuned systems talking past each other. It also runs a control, PAA-MCB: SAX's PAA cells cut at learned per-position quantiles. Going from SAX to PAA-MCB changes only the bin table, and going from PAA-MCB to SFA changes only the front end, so the two sources of any difference can be told apart.

What it found, on EURUSD H1 with 120 queries and paired standard errors: SFA's lead in nearest-neighbor recall is large where the bit budget buys a deep alphabet over few positions (8 to 10 points at a = 8 or 10 with six or eight letters), and it disappears as the budget is spread over many shallow positions (w = 16 or 24 at a = 4 or 6, where the two tie). SAX did not come out ahead in any configuration, under three different fit/measure splits, or in three separate two-year periods. At w = 8, a = 8 about half of SFA's lead comes from the learned bins and half from the Fourier transform; at w = 24 PAA with learned bins beats SFA outright.

Two negative results are worth knowing. SFA flips more letters than SAX when the window is disturbed, and that is caused by the front end (PAA averages the noise away), not by SAX under-using its alphabet. And a tighter lower bound is not the same thing as better retrieval: SFA's bound was the tightest in every run, including configurations where recall was tied.

InpEndTime and InpSplit pin the data and the split, so every number in the article can be reproduced.

Layout

Include/SFA/SFATransform.mqh   Fourier front end and MCB binning
Include/SFA/SFAAnalogs.mqh     analog search with the lower bound
Include/SAX/SAXTransform.mqh   SAX, included for the comparison
Indicators/SFA/SFAAnalog.mq5   the indicator
Scripts/SFA/SFAValidate.mq5    validation harness
Scripts/SFA/SFACompare.mq5     SAX, PAA-MCB and SFA on identical windows

Run SFAValidate.mq5 first, then SFACompare.mq5 on your own symbol.

Disclaimer

Educational code. Past behaviour of any model or dataset says nothing about future results. Test on your own data and broker conditions before drawing conclusions.