Loading…

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 · MT4 · v1.0 · Free

About Asset Class Exposure Cap

Asset Class Exposure Cap is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message and 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.ex4, AssetClassExposureCap.mq4, AssetClassExposureCap.txt.

Settings

SettingDefaultWhat it does
Metals symbolsXAUUSD,XAGUSDComma-separated symbols classed as Metals
Indices symbolsUS30,US500,USTEC,UK100,GER40,JP225Comma-separated symbols classed as Indices
Majors symbolsEURUSD,GBPUSD,USDJPY,USDCHF,USDCAD,AUDUSComma-separated symbols classed as Majors
Max positions per class3Max simultaneous open positions per class (0 = no count cap)
Max lots per class1.00Max total lots per class (0.0 = no lot cap)
Magic filter-1Magic number filter, -1 = watch every magic number
Auto enforcetrueActively close the newest breaching position; false = warn only
Slippage pips5Slippage tolerance for enforcement closes, in pips
Max retries5Attempts per close before giving up
Retry wait ms500Pause between attempts, milliseconds

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: Gold (XAUUSD) · Alerts · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria