Correlation Heatmap Renderer
A correlation matrix or a per-symbol performance table is easy to compute and hard to read as a wall of numbers - the pattern that matters is which cells are extreme, and that is exactly what a human eye picks out of colour faster than out of digits. This header draws that matrix directly onto the chart as a grid of coloured rectangle-label objects with row and column headers and an optional numeric value in each cell. Two implementation decisions shape it, both true on either platform. First, a heatmap's row and column counts are both only known at runtime, and neither platform allows anything but the leftmost dimension of a true 2D array to be dynamic - a genuine double values[][] cannot be sized to an arbitrary rows-by-columns on either. The matrix is stored flattened into one 1D array instead, indexed manually as values[row*cols+col], the standard workaround for a dense rectangular grid. Second, colour interpolation reads the color type through explicit bit masks rather than assuming byte order. Both platforms store a color value as 0x00BBGGRR (the Windows COLORREF layout) - low byte red, not blue - so a channel blend written without accounting for that order silently swaps red and blue. That never throws a compile or runtime error, it just paints the wrong colour, which is a genuinely common bug in chart-drawing code that nobody notices until they compare a screenshot against what they expected. The colour scale itself is a three-stop diverging gradient (low -> mid -> high), the shape a correlation table needs since zero is a meaningful centre rather than one end of a plain range - unlike a simple two-colour scale, a value near zero renders near-white regardless of whether the overall range happens to be symmetric. Notes and limitations - values[] must already be flattened row-major (values[row*cols+col]) and must contain exactly rows*cols elements - there is no bounds check against a mismatched size, a short array will read past its end. - HeatmapDraw() reuses existing objects by name (via ObjectFind) rather than deleting and recreating them, so calling it repeatedly on a timer to refresh a live matrix does not flicker - only the colour and text update. - Every object this header creates lives under prefix; a real EA or indicator should call HeatmapClear(prefix) in OnDeinit() so the grid does not outlive the program that drew it. The demo deliberately leaves its final heatmap on the chart for the screenshot rather than doing this, since it is a one-shot script rather than a long-running program. - No axis sorting, clustering or legend is drawn - this renders the matrix exactly in the row/column order it is given.
Script · MT4 · v1.0 · Free
About Correlation Heatmap Renderer
Correlation Heatmap Renderer is a script for MetaTrader 4. It shows several symbols in one panel. It has 3 settings, such as Cell size, X and Y. MQL source code included.
Files in the download: HeatmapRenderer.mqh, HeatmapRenderer.txt, HeatmapRendererDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Cell size | 46 | Pixel size of each square cell |
| X | 20 | Chart-space X of the heatmap's top-left corner |
| Y | 20 | Chart-space Y of the heatmap's top-left corner |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Grid · Dashboards & Scanners · MT4 Script · MQL4 Source Code