Correlation Matrix and Open Position Exposure
- 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.2
- Activations: 5
Correlation Matrix and Open Position Exposure shows two things in one panel on your MetaTrader 5 chart: a heat map of how closely up to 20 symbols have moved together, and a list of the pairs of your open positions that are highly correlated. A pair is marked either as same-direction concentration (the positions tend to win or lose together, so their risks add up) or as offsetting (they tend to cancel each other out).
It is meant for traders who hold several positions at once and want to see when, for example, a long EURUSD and a long GBPUSD are close to one bigger position. It is a display tool only: it gives no buy or sell signals and never opens, modifies or closes a position or order.
Features
- Correlation heat map for up to 20 symbols: the first 20 symbols in Market Watch, or your own comma-separated list (broker prefix and suffix detected automatically or set by hand). Symbols with open positions are always added (can be turned off).
- Timeframes M15, M30, H1, H4 and D1, each on or off (default H1, H4, D1). Switch between them with the tabs on the panel.
- Open position exposure on the timeframe you choose (default H1): net lots per symbol (buy +, sell -, a hedge on the same symbol is netted), a risk estimate per symbol, and every pair of held symbols with |r| at or above your threshold (default 0.70), marked "Same direction" with the combined risk or "Offsetting" with the remaining risk.
- Totals: the simple sum of the risks and an estimate that takes the correlations into account, both also as % of equity.
- Optional filter by magic number, to look only at the positions of one EA.
- Click a symbol row to switch the chart to that symbol. Collapse button, three sizes, light or dark colors from the chart background, four corners; several copies in the same corner are stacked.
- Alert when a new same-direction pair reaches a combined risk of X % of equity (off by default). Pop-up and push notification.
- Two buffers for your own EAs (iCustom).
- English or Japanese (Auto follows the terminal language).
Main Inputs
- Symbols: Market Watch or list, the list, prefix, suffix, maximum symbols (2-20), always include held symbols.
- Correlation: the five timeframes, period (number of bar-to-bar changes, 20-500, default 100).
- Open position exposure: show or hide, timeframe for the check, threshold |r| (0.30-0.99), magic number (-1 = all positions), maximum pair lines (1-30).
- Alerts: on or off, minimum combined risk in % of equity (0 = any pair), pop-up, push.
- Panel: language, corner, offsets, size, colors, notes under the panel, start collapsed.
- 30 inputs in 6 groups.
How It Is Calculated
- Closed bars only; the current bar is never used. For each pair of symbols only bars with the same open time on both symbols are used. From the latest "period + 1" common bars the indicator builds the close-to-close changes (close / previous close - 1) and calculates the Pearson correlation coefficient r.
- If two symbols have fewer common bars than the period (different trading hours, short history), r is calculated from what exists and shown faded with "~" as a reference value. With fewer than 10 changes it shows "-".
- Risk per symbol = net lots x the money value of one daily ATR(14) move, in the account currency. This is the size of one typical daily move, not a stop loss and not a maximum loss.
- For a pair, direction A x direction B x the sign of r decides the kind: positive = same direction (combined = sum of the two risks), negative = offsetting (remaining = difference).
- The estimate with correlation is the square root of E'CE (E = signed risks, C = the correlation matrix of the exposure timeframe). It is a rough figure, not a statistical forecast.
Notes and Limits
- Correlation describes how the symbols moved in the chosen period. It changes over time, can break down quickly (for example around major news) and is not a forecast. Colors show the sign and size of r; they are not buy or sell colors. Past values do not guarantee future results. Trade decisions are your own.
- The risk figures are an estimate based on one daily ATR. Real moves can be much larger, and gaps, slippage and spread are not included. They are not a limit on your loss.
- Only open positions are counted; pending orders are not. A held symbol that is not in the matrix is marked * (correlation unknown).
- Market Watch mode uses the first 20 symbols in Market Watch. To choose the symbols, use list mode. In list mode, symbols not in Market Watch are added to receive data and removed again when the indicator is removed (unless a chart, position or order uses them).
- The first time a symbol is used, the terminal may need some time to load its history; until then the panel shows that it is loading.
- Panel size: with 20 symbols and size Medium the panel is about 560 pixels high, with many positions about 630 to 800 pixels. On a lower chart the panel shrinks (text down to 75%), puts the exposure lines that do not fit into "+N more lines" (the line with the sum of risks stays), and if it still does not fit, shows only the top part with the title marked. To make it smaller: size Small, fewer symbols, notes off, fewer pair lines, or collapse it.
- One-click trading panel: in the top-left and bottom-left corners the panel moves out of its way automatically, also when you turn it on or off (within about one second). The right corners do not overlap it.
- Alerts: the same pair is reported at most once every 30 minutes. Pairs that already exist when the indicator starts are not reported. No alerts in the Strategy Tester or from iCustom. Push notifications need the terminal's settings.
- iCustom: buffer 0 = number of same-direction pairs, buffer 1 = the largest combined risk among them in % of equity. The values advance only when ticks arrive, so they can take from a few seconds to about 45 seconds to appear. Buffer 1 is EMPTY until the daily ATR is loaded and when there is no same-direction pair. Pass inputs in their valid ranges. In the Strategy Tester without visual mode the indicator does nothing (EMPTY).
- Strategy Tester visual mode: if there are no positions, the panel shows demo positions (marked as tester only) so that the exposure section can be seen. No orders are placed.
- Keep the input "Debug" off; it writes a check file for development.
Compatibility and Support
- MetaTrader 5 only. The MetaTrader 4 version is a separate product. Works on any chart with the forex, metal, index and other symbols your broker provides.
- No DLLs, no internet access.
- Support through MQL5 messages, reply within 3 business days: installation, settings and bug reports. Questions about market views, trade decisions or which positions to hold cannot be answered.
