Discussing the article: "Building Your Personal Expert Advisor (Part 2): Risk Management and Dynamic Lot Sizing"

 

Check out the new article: Building Your Personal Expert Advisor (Part 2): Risk Management and Dynamic Lot Sizing.

This part implements risk-based position sizing for the EA. Lot size is derived from account balance, a chosen risk percent, and ATR-based stop distance, then confined and rounded to the broker's volume rules and minimum stop levels. An optional drawdown-aware layer reduces risk during equity declines. Readers get a reproducible sizing function that keeps per-trade risk consistent and orders acceptable to the server.

In Part 1, you have already improved the basic MA‑crossover EA into a technically sound skeleton: it processes signals once per bar, isolates positions with a Magic Number, sets ATR‑based stops, and handles basic errors. One critical problem remains for algorithmic traders and EA developers: the EA still uses a fixed LotSize. That single choice breaks risk control — monetary risk per trade drifts with volatility (ATR widens), does not scale with account balance, and never responds to drawdowns; it can also cause otherwise valid orders to be rejected by brokers because of minimum stop distances or lot rules.

This article fixes that gap by tying position size to a chosen percent of account equity (using the ATR stop as the sizing input), validating stops and volumes against the broker's SYMBOL_* constraints, and adding an optional adaptive risk layer that reduces exposure during drawdowns. The result is a reusable MetaTrader 5 position‑sizing module that keeps $‑risk predictable and executable without changing the strategy logic.

Scope of This Article

By the end of this part, we will have:

  • Replaced the fixed LotSize input with risk-based position sizing.
  • Derived lot size from account balance, risk percentage, and ATR-based stop distance.
  • Added validation against broker-imposed minimum stop distance and volume constraints.
  • Introduced an adaptive risk layer that reduces exposure automatically during drawdowns.

The techniques here are not specific to a moving average crossover strategy. The same sizing logic can apply to most EAs that calculate a stop-loss before sending an order.


Author: Solomon Anietie Sunday