Currency Exposure Matrix
A book long EURUSD, long GBPUSD and long EURGBP looks diversified - three different symbols, no obvious overlap. Decomposed into currencies it is something else entirely: EUR is long from two directions at once, and the real net exposure to GBP is much smaller than either single GBP-containing position suggests. Nothing about that is visible while looking at positions symbol by symbol. It is only visible once every position is split into its base and quote currency and the signed amounts are summed. That is what this library does. Every open BUY adds exposure to its base currency and removes exposure from its quote currency, in the amounts that symbol's own contract size implies; every SELL is the mirror image. The running totals are kept in currency units - "+250,000 EUR", not converted to account currency - because that conversion would need a live cross rate for every currency touched and would bury the one figure this tool exists to show: how much of each currency the book actually holds, before anyone converts anything. Contract size is read per symbol from the broker (MODE_LOTSIZE on MQL4, SYMBOL_TRADE_CONTRACT_SIZE on MQL5), never assumed to be the standard 100,000. Metals, mini contracts and index CFDs all use different contract sizes, and assuming the FX-standard figure would silently misprice every one of them the moment a mixed-instrument book was scanned. The header is self-contained. No dependencies, no DLLs - a small struct-per- currency table the caller owns, and plain functions to build and read it. Notes and limitations - Currency parsing assumes the standard 6-character FX naming convention (base then quote, e.g. "EURUSD"), reading only the first six characters - a broker suffix such as "EURUSDm" still parses correctly. Non-FX symbols (metals, indices, crypto CFDs) do not decompose into two ISO currency codes this way; their exposure will be attributed to whatever six characters their symbol name happens to start with, which is usually meaningless. Filter those symbols out before building the table, or treat their rows as noise. - Exposure is reported in raw currency units, not account currency. Comparing two rows directly (e.g. "is +250,000 EUR bigger than -180,000 GBP") requires a live cross rate the library deliberately does not fetch - that conversion belongs to the caller, who knows which rate source and staleness tolerance is appropriate for their use. - Pending orders are skipped entirely - only OP_BUY and OP_SELL carry real exposure. A pending order about to trigger is not yet a position. - The demo's synthetic book example uses a fixed illustrative contract size because its three example symbols may not all be tradable on the machine running the script. A live scan through CemBuildFromOpenOrders (MQL4) or CemBuildFromOpenPositions (MQL5) always reads the real contract size per symbol from the broker, as it must. - The table size is fixed by the caller at ArrayResize time. CemAddExposure and CemBuildFromOpenOrders both report failure (rather than silently dropping data) when a table this small overflows - size it generously (32 rows comfortably covers every currency traded on a retail FX book).
Script · MT4 · v1.0 · Free
About Currency Exposure Matrix
Currency Exposure Matrix is a script for MetaTrader 4. It shows several symbols in one panel. It has 1 setting, such as Magic filter. MQL source code included.
Files in the download: CurrencyExposureMatrix.mqh, CurrencyExposureMatrix.txt, CurrencyExposureMatrixDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Magic filter | -1 | Magic number to scan for in part two, -1 = every open order |
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: EURUSD · GBPUSD · Dashboards & Scanners · MT4 Script · MQL4 Source Code