Discussing the article: "Building Your Personal Expert Advisor (Part 4): Risk Management III—Risk Models and Order Execution"

 

Check out the new article: Building Your Personal Expert Advisor (Part 4): Risk Management III—Risk Models and Order Execution.

The EA now defines risk by percentage, fixed cash, or fixed lot and can measure percentage against balance or equity. It supports market, limit, and stop orders, sizes from the planned entry, and enforces spread‑aware stop minima. Additional safeguards include downward volume rounding, explicit handling when the minimum lot exceeds target risk, and pending‑order distance/expiry checks, organized under a Plan–Validate–Execute structure.

The EA from the previous part already sizes trades from a risk input and enforces broker volume and margin limits — but it did so while quietly assuming two things: "risk" always means a percentage of the account, and every trade enters immediately at the current price. Those assumptions break practical use-cases: fixed-dollar risk, sub‑allocated strategies, or any workflow that relies on pending (limit/stop) entries. When you try to use those, the EA sizes stops and lots against the wrong price or silently changes the effective risk, so identical signals can produce different volumes, stop distances, and trade frequency depending on timing and account state. This part makes those assumptions explicit choices in the code and delivers a clear, testable interface: multiple risk models (percent/cash/fixed‑lot), percent measured against balance or equity, market/limit/stop entries, sizing from the intended entry price, and a strict separation between planning, validation and execution.

This is the most involved part so far. Earlier parts added safeguards to existing behavior. This part changes what the EA is allowed to do and also corrects assumptions made earlier.

Author: Solomon Anietie Sunday