Discussing the article: "Motifs and Discords: Building a Matrix Profile from Scratch"

 

Check out the new article: Motifs and Discords: Building a Matrix Profile from Scratch.

We build the Matrix Profile for MQL5 from the ground up and keep it numerically stable on real prices. The library includes rolling statistics, a radix-2 FFT powering MASS, and a STOMP self-join, with results matched to stumpy. A compact facade, an indicator that draws the profile and flags discords, and a demonstration Expert Advisor show how to read and use the signal in practice.

Before the theory, here is the payoff. Attach the finished indicator to a EURUSD H1 chart and it computes one Matrix Profile over the last several hundred bars, then draws it in a subwindow. The line dips where the market repeated a shape and spikes where it did something new, and the top discords, each a roughly two-day stretch unlike anything else nearby, are marked on the chart.

 The Matrix Profile indicator in a subwindow under a EURUSD H1 chart, with the profile line and a discord marker


The numbers behind that picture are worth stating, because they set this tool apart from a rare-event detector. On EURUSD H1, using a 48-bar window over 500 bars, the profile ranges from about 2.3 (tightest repeated pair) to about 6.3 (strongest discord), with a median around 4.4. The theoretical ceiling is sqrt(2*48) ≈ 9.8. The whole profile, 453 windows and roughly 194,000 distance evaluations, computes in a handful of milliseconds per recompute, below what the millisecond timer can resolve. The signal is rich and always present: unlike a bubble detector that reads zero on most days, the Matrix Profile always has a motif and a discord to show you. That is what this article delivers. The rest explains how.

Author: Hammad Dilber