Loading…

Correlation Matrix Panel

"Diversifying" across several open positions is only real diversification if those symbols are not, for the moment, moving as one trade. Two pairs that are usually independent can spend a week correlated at 0.9 and give back the appearance of spread risk while both hit stop within the same minute. This panel makes that visible before it happens, computing genuine Pearson correlation - not a rough visual eyeball of two overlaid lines - between every pair in a symbol list and laying the results out as a coloured grid. The correlation itself is calculated the standard way: bar-to-bar percentage returns for each symbol over InpLookbackBars bars, then the normalised covariance between each pair of return series. Using returns rather than raw price levels is what makes this a proper statistical correlation instead of a comparison that would be dominated by each symbol's own price scale and long-term drift. Cells are coloured on a diverging scale - full green at +1 (moves together), full red at -1 (moves opposite), grey through the middle - so the strength of a relationship is visible at a glance, not just its sign. Notes and limitations - Returns are built strictly from closed bars (shift 1 upward), never shift 0, so the matrix cannot repaint on a still-forming bar. - Assumes every listed symbol shares the chart's chosen timeframe closely enough for their bar closes to line up - reasonable for standard forex majors and crosses on the same timeframe, but correlation between symbols with very different session hours (an index against a forex pair, for instance) will be approximate. - A symbol with insufficient history (fewer than InpLookbackBars+2 bars) shows "n/a" in every cell of its row and column rather than a misleading zero. - Correlation measures how closely two symbols have moved together recently, not why - it says nothing about causation and can shift quickly around news events. - No alerting in this version; it is a read-at-a-glance panel, refreshed continuously.

Indicator · MT4 · v1.0 · Free

About Correlation Matrix Panel

Correlation Matrix Panel is an indicator for MetaTrader 4. It has 10 settings, such as Symbol list, Symbol suffix and Timeframe. MQL source code included.

Files in the download: CorrelationMatrix.ex4, CorrelationMatrix.mq4, CorrelationMatrix.txt.

Settings

SettingDefaultWhat it does
Symbol listEURUSD,GBPUSD,USDJPY,USDCHF,AUDUSD,USDCAComma separated symbol list (8 max recommended)
Symbol suffixBroker suffix appended to every symbol (e.g. ".pro"), leave blank if none
TimeframePERIOD_H1Timeframe the returns are measured on
Lookback bars100Number of bar-to-bar returns used per correlation
CornerCORNER_LEFT_UPPERPanel corner
X distance10Panel horizontal offset, pixels
Y distance20Panel vertical offset, pixels
Font size8Cell font size
Cell size46Width and height of each grid cell, pixels
Label width60Width reserved for the row-header symbol names, pixels

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the indicator from the Navigator onto a chart and adjust the settings.

Download the PDF guide

Tags: Grid · MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria