Loading…

Concentration Index Report

Five positions on five different symbols looks diversified until four of them are EURUSD, EURGBP, EURJPY and EURCHF, and the book is really one bet on the euro wearing four disguises. Counting positions or even counting lots does not catch this, because a "diversified" account with equal lot sizes across correlated pairs is not diversified in any way that matters when that one currency moves. This script computes the Herfindahl-Hirschman Index, a standard concentration measure: take each group's share of total exposure as a percentage, square it, and sum. A perfectly even split across many groups produces a low score; one group holding everything produces the maximum, 10000. It is run twice - once grouping by symbol, once by currency, with every forex pair contributing its exposure to both the base and the quote currency it touches - so a book that looks spread by symbol can still be shown as concentrated by currency, which is usually the number that matters. The exposure weight itself is where this kind of script commonly goes wrong: multiplying lots by an assumed 100000 contract size produces a plausible-looking but false notional figure the moment gold, an index or a non-standard lot size is in the book. This script instead reads MODE_MARGINREQUIRED from the broker for each symbol, which already reflects that instrument's real contract size and leverage, and weights exposure by margin required per lot times the position's own volume. If a broker genuinely returns nothing for that mode, the script falls back to weighting by lot count alone and says so plainly in the log rather than quietly using a number that might be wrong. Notes and limitations - The currency roll-up assumes every recognised pair is a clean six-letter base-plus-quote code before any broker suffix; anything else, including gold and indices, is treated as its own single-currency group. - Margin required per lot can itself change with leverage tiers or volume-based margin schemes some brokers apply; the score reflects the broker's answer at the moment the script runs, not a fixed rate. - This is a snapshot, not a running monitor. Re-run it after the book changes to see an updated score. - A high HHI is a structural observation, not a trading signal on its own - a genuinely diversified account can still choose to run one large concentrated position on purpose.

Script · MT4 · v1.0 · Free

About Concentration Index Report

Concentration Index Report is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 4 settings, such as Include pending orders, Write report file and Alert on high concentration. MQL source code included.

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

Settings

SettingDefaultWhat it does
Include pending ordersfalseInclude pending order volume in the exposure weights
Write report filetrueWrite the symbol and currency breakdown to CSV
Alert on high concentrationtrueAlert when the book is concentrated
Concentrated threshold2500.0HHI (0-10000 scale) above which the book counts as concentrated

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 → Scripts.
  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 script onto a chart to run it once.

Download the PDF guide

Tags: Risk & Lot Size · EURUSD · Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria