Asset Class Exposure Cap
Position limits are usually set per symbol, which misses the more common way an account gets over-concentrated: five different index CFDs, or gold plus silver plus a mining-heavy basket, all moving on the same underlying driver at once. A trader watching a per-symbol limit sees five small, individually reasonable positions. The account is actually carrying one large, undiversified bet. This EA reads three comma-separated symbol lists on start - metals, indices and majors - classifies every open position into whichever list its symbol appears in, and treats anything not listed as its own "other" class. It then enforces two independent caps per class: a maximum position count and a maximum combined lot size. When a class goes over either cap, it closes the newest position in that class - the one that actually pushed it over the line - and repeats until the class is back within both limits. It watches the whole account, not one chart's symbol, and by default watches every magic number so it catches concentration building up across several EAs or manual trades at once. A magic number filter narrows that to one strategy's own positions if that is what you want capped instead. Notes and limitations - This EA never opens a position. It only classifies and, if enabled, closes existing ones that push a class over its configured cap. - "Other" is not a free pass - any symbol not present in one of the three lists lands there, and the same two caps apply to it as to any class. - Enforcement always closes the newest position in the breaching class, never the oldest or the largest - this is a deliberate, predictable rule, not an attempt to pick the "best" one to remove. - With InpAutoEnforce off, this becomes a pure monitor: it reports breaches without acting on them, useful for watching before turning enforcement on. - If AutoTrading is off, a breach is logged but cannot be enforced.
Expert advisor · MT5 · v1.0 · Free
About Asset Class Exposure Cap
Asset Class Exposure Cap is an expert advisor (trading robot) for MetaTrader 5. It is set up for gold (XAUUSD). It has 10 settings, such as Metals symbols, Indices symbols and Majors symbols. MQL source code included.
Files in the download: AssetClassExposureCap.ex5, AssetClassExposureCap.mq5, AssetClassExposureCap.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Metals symbols | XAUUSD,XAGUSD | Comma-separated symbols classed as Metals |
| Indices symbols | US30,US500,USTEC,UK100,GER40,JP225 | Comma-separated symbols classed as Indices |
| Majors symbols | EURUSD,GBPUSD,USDJPY,USDCHF,USDCAD,AUDUS | Comma-separated symbols classed as Majors |
| Max positions per class | 3 | Max simultaneous open positions per class (0 = no count cap) |
| Max lots per class | 1.00 | Max total lots per class (0.0 = no lot cap) |
| Magic filter | -1 | Magic number filter, -1 = watch every magic number |
| Auto enforce | true | Actively close the newest breaching position; false = warn only |
| Slippage pips | 5 | Slippage tolerance for enforcement closes, in pips |
| Max retries | 5 | Attempts per close before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Gold (XAUUSD) · MT5 Expert Advisor · MQL5 Source Code