Discussing the article: "Building Your Personal Expert Advisor (Part 5): Risk Management IV—Basket Risk and Strategy-Specific Sizing"

 

Check out the new article: Building Your Personal Expert Advisor (Part 5): Risk Management IV—Basket Risk and Strategy-Specific Sizing.

Part 5 moves risk control from single trades to a basket-level framework. The EA aggregates its own positions, computes volume‑weighted entry, floating P/L including swap, and used margin, then enforces limits on combined loss, margin, position count, and time underwater, while logging maximum adverse excursion. A companion mean‑reversion EA demonstrates target‑based sizing and caps on implied risk that remains hidden when trades are evaluated in isolation.

Your EA from the previous part already knows how to place a “correct” trade: compute lot size from a risk budget, set a valid stop, and verify free margin. The gap is that every one of those checks answers a question about a single candidate trade — and cannot see what else the account is carrying. Two or three individually valid trades on the same symbol (stacking, averaging, repeated signals, or hedged legs) can quietly turn 1% per trade into 3–6% total exposure, consume disproportionate margin, and leave capital “underwater” for longer than intended.

This part closes that gap by treating everything the EA owns as one basket: it measures total volume, a volume‑weighted average entry, floating P/L including swap, estimated used margin, position count and oldest open time, plus MAE/MFE and peak position count for diagnostics. Those aggregates power two classes of controls: every‑bar protections (aggregate loss cut, time stop, MAE tracking) and pre‑trade admissions (position/ order ceilings, margin ceiling, and implied‑risk caps). Because some sizing models require a price target and therefore make risk an output rather than an input, a small companion mean‑reversion demo EA illustrates target‑based sizing and the additional per‑leg and per‑basket implied‑risk checks the model needs.


Author: Solomon Anietie Sunday