Four Expert Advisors on the same symbol, each one honest on its own. Each checks "do I already have a position?" with its own magic number, sees none, and enters. Each re-enters on every new bar while already positioned, because the check was per-EA and the fleet was not. On a demo account this reached 22 contracts on a symbol meant to carry one, and an external watchdog had to close 16 positions in a single morning - paying the spread of openings that should never have happened, and filling the history with tiny trades that were nobody's decision.
Closing afterwards is the wrong layer. The cap belongs at the door: the order is refused before it exists.
What the library does. ExposureCap::Allowed(symbol, requestedLots, cap, who) sums the volume of every open position on the symbol - all magic numbers, manual trades included - and answers whether adding the requested lots would stay within the cap. On refusal it logs one line with the three numbers (held, requested, cap) and the caller's name, so the reason is in the experts log and not in anyone's memory. ExposureCap::Held(symbol) returns the gross volume held; ExposureCap::Room(symbol, cap) returns how much is left under the cap. A cap of zero or less disables the check.
How to use it. Include the file and put if(!ExposureCap::Allowed(_Symbol, lots, InpCap, "MyEA")) return; in front of every OrderSend in every EA on the account, with the same cap. The fleet stops adding to itself.
What it does not do. It is deliberately simple: gross exposure on the symbol, no netting of longs against shorts, no per-EA quota. Gross exposure is the number that breaks accounts; refinements can be layered on top. And it is a check, not a lock: two EAs deciding on the same tick can both read "0 held" and both pass. In practice EAs on different charts decide on different ticks, and one refusal per bar is what was observed - but that limit is stated here on purpose.
Demo script inputs: InpCap (1.0) - the gross cap for the chart symbol, in lots; InpRequested (1.0) - the lots a hypothetical entry would request. The script prints held / cap / room for the current symbol, shows the refusal line for a request of room + 1, and trades nothing.