Correlation Matrix and Open Position Exposure MT4
- Indicators
-
Kazuma Uezono
MQL5 / MQL4 / Pine Script v6 developer and active trader.
Seller on the MQL5 Market (indicators for MT4/MT5).
Services:
- TradingView Pine Script to MT5/MT4 conversion (bar-by-bar matching, with tester report)
- MT4 to MT5 migration - Version: 1.0
- Activations: 5
Do several of your open trades really add up to one larger bet? Correlation Matrix and Open Position Exposure MT4 answers this on your MetaTrader 4 chart. One panel combines a correlation heat map of up to 20 symbols with a check of your open market orders: each highly correlated pair of held symbols is labelled "Same direction" (the risks stack) or "Offsetting" (one tends to cancel the other).
The indicator only displays information. It sends no signals and it never opens, changes or closes an order. Correlation values come from past prices and are not a forecast.
Features
- Exposure check of your open buy and sell orders on one timeframe of your choice (H1 by default): net lots per symbol, where buy is plus, sell is minus and opposite orders on one symbol are netted; an estimated risk per symbol; and all held pairs whose |r| reaches the threshold (0.70 by default), with the combined risk of a same-direction pair or the remaining risk of an offsetting pair.
- Two totals: risks simply added together, and an estimate that uses the correlations. Both are also shown as a share of equity.
- Heat map of up to 20 symbols, taken from the top of Market Watch or from a list you type (separated by commas; broker prefix and suffix are found automatically or can be entered). Symbols you hold are always included unless you switch this off.
- Any of M15, M30, H1, H4 and D1 can be calculated (H1, H4 and D1 by default); tabs on the panel switch between them.
- Magic number filter, if you want to check only the orders of one EA.
- Click a row to load that symbol on the chart. The panel can be collapsed, comes in three sizes, picks light or dark colors from the chart background, sits in any corner and stacks with other copies in the same corner.
- Optional alert (off by default) when a new same-direction pair reaches a combined risk of a chosen percentage of equity, by pop-up and/or push notification.
- Two indicator buffers that other programs can read with iCustom.
- Panel text in English or Japanese, chosen automatically from the terminal language unless you set it.
How It Is Calculated
- The forming bar is ignored; only closed bars count. Two symbols are compared only on bars that opened at the same time on both. The last "period + 1" shared bars give a series of close-to-close returns (close divided by the previous close, minus 1), and r is their Pearson correlation.
- When the shared bars are fewer than the period, r uses what is available and is drawn faded with "~"; it is a reference value only. Below 10 returns the cell shows "-".
- Estimated risk of a symbol: its net lots multiplied by what one daily ATR(14) move is worth in the deposit currency. It describes a typical day, not a stop loss and not the most you can lose.
- Pair type: the sign of (direction of A) x (direction of B) x r. Plus means same direction and the two risks are added; minus means offsetting and the difference remains.
- The correlation-aware total is sqrt(E'CE), with E the signed risks and C the correlation matrix of the exposure timeframe. Treat it as a rough guide, not as a statistical prediction.
- Calculation, inputs and alert rules are the same as in the MetaTrader 5 edition; the differences below come from MetaTrader 4 itself.
Main Inputs
- Symbols group: source (Market Watch or list), symbol list, prefix, suffix, how many symbols (2-20), add held symbols.
- Correlation group: one switch per timeframe and the period, i.e. the number of returns (20-500, default 100).
- Open position exposure group: section on or off, timeframe of the check, |r| threshold (0.30-0.99), magic number (-1 for all orders), how many pair lines (1-30).
- Alerts group: switch, minimum combined risk as % of equity (0 for any pair), pop-up, push.
- Panel group: language, corner, X and Y offset, size, color scheme, notes line, collapsed at start.
- In total 30 inputs, arranged in 6 groups.
Notes and Limits
- Only market orders (buy and sell) are counted. Pending orders such as limits and stops are ignored. A held symbol that is missing from the heat map gets a * because its correlation cannot be judged.
- MetaTrader 4 redraws the panel when a tick arrives or when you click or scroll. New values may therefore appear only with the next tick. On a weekend or any time without ticks, the loading message shown right after you attach the indicator can stay until you touch the chart.
- Bar times depend on the broker. On some MT4 servers, metal and index H4 bars start one hour later than forex H4 bars, so H4 pairs between them have few shared bars and show "~". An index whose H1 and H4 bars start at a quarter past the hour shares no bars with forex symbols on those timeframes and shows "-" (D1 is normal). The calculation itself does not change; it always uses bars with identical times.
- A correlation is a description of the chosen past period. It shifts over time, can fall apart quickly (for example around big news) and does not predict anything. Heat map colors show the sign and strength of r, never a buy or sell. Past values do not guarantee future results, and every trade decision is yours.
- The risk numbers estimate one ordinary daily move. Real moves can be far larger, and gaps, slippage and spread are not included, so they never cap your loss.
- Market Watch mode takes the first 20 symbols listed there; use list mode to choose them yourself. In list mode, symbols missing from Market Watch are added so that data arrives, and removed again when you remove the indicator, unless a chart or an order still needs them.
- Panel height: about 560 pixels for 20 symbols at size Medium, and roughly 630 to 800 pixels when you hold many symbols. On a shorter chart the panel scales down (text to 75% at the smallest), folds extra exposure lines into "+N more lines" while keeping the risk total visible, and as a last step shows only its upper part with a mark in the title. Size Small, fewer symbols, notes off, fewer pair lines or the collapse button make it smaller.
- One-click trading panel: when the indicator sits in the top-left or bottom-left corner, it keeps clear of that panel and follows within about a second when you show or hide it. The right-hand corners never meet it.
- Alerts: one message per pair per 30 minutes at most, nothing for pairs that already existed when the indicator started, and none in the Strategy Tester or from iCustom. Push needs the terminal's notification settings.
- iCustom: read shift 0. Buffer 0 holds the number of same-direction pairs and buffer 1 the largest combined risk among them, in % of equity. The values advance only with ticks; the first time many symbols are loaded it can take from a few seconds to more than a minute. Buffer 1 stays EMPTY until daily ATR data is ready and whenever no same-direction pair exists. Pass inputs within their valid ranges: with an invalid input MetaTrader 4 writes an initialization error to the log every time it is called. In the Strategy Tester without visual mode the indicator stays idle (EMPTY).
- Leave the "Debug" input off; it is only for writing a development check file.
Compatibility and Support
- For MetaTrader 4. The MetaTrader 5 edition is a separate product. Usable on any chart and with the forex, metal, index and other symbols your broker offers.
- No DLL calls and no internet connection.
- Questions are answered through MQL5 messages within 3 business days, for installation, settings and bug reports. Market opinions, trade decisions and advice on which positions to hold are outside the support.
