You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Check out the new article: Symbol Correlation Monitor with Live Heatmap in MQL5.
This work delivers an MQL5 Expert Advisor that reads open-position symbols, builds return series, and computes a rolling Pearson correlation matrix, displayed as a CCanvas heatmap. Off-diagonal pairs that meet a warning threshold are bordered for quick scanning. The code details return processing, correlation arithmetic, and matrix indexing, with a verification script, helping you track shifting co-movements across your active book.
A trader can hold five positions in five symbols and still not be diversified. If two or three of those symbols tend to move together, a loss on one is very likely to show up as a loss on the others at the same time, which means the account's real risk concentration is much higher than the position count alone suggests. Standard trade reports have nothing to say about this, since they look at each position in isolation.
This matrix measures how closely symbols' price returns move together. It does not measure the portfolio's actual risk, since it does not account for position size, direction, or how much each position would gain or lose per point of movement. Two highly correlated symbols held in opposite directions can reduce risk rather than concentrate it. Treat the matrix as a signal that two symbols are worth a closer look, not as a finished risk calculation.
Pearson correlation answers a simple question: over a recent window, how closely did the returns of two symbols move together? A value near 1.0 means they moved almost in lockstep. A value near -1.0 means one tended to rise when the other fell. A value near zero means no clear linear relationship at all. None of this is exotic mathematics, but correlation between two symbols is not a fixed fact. It drifts, sometimes sharply, as market regimes shift, so a number computed once at the start of the day can already be stale by the afternoon.
This article builds an Expert Advisor that keeps the correlation matrix close to current. It reads the symbols of all open positions, builds rolling return windows from closed bars, computes the pairwise correlation matrix, and draws it as a heatmap on the chart. The matrix recomputes on every new bar and on every change to the open position set, not on every tick. Every symbol pair whose correlation reaches a configurable threshold gets a visible warning border, so a trader glancing at the panel does not need to read every number to see where the risk is concentrated.
Before the implementation: a correlation matrix describes the recent past, not a forecast. A pair that was highly correlated last week can decouple this week, and a pair that looks independent today can start moving together the moment a shared driver, a rate decision, or a risk-off event shows up. This monitor is built to make that drift visible soon after it happens, not to predict when it will happen next. Because every return is measured between closed bars, the matrix always reflects the most recently completed bar, not the instant a correlation shift begins.
Author: Ushana Kevin Iorkumbul