Discussing the article: "Account-Wide Position Sizing in MQL5: Capping Each New Trade by the Risk Already Open"

Check out the new article: Account-Wide Position Sizing in MQL5: Capping Each New Trade by the Risk Already Open.

When an EA trades several symbols, each new lot size must account for the risk already open. CRiskBudget returns the largest volume that five caps allow: risk per trade, open risk budget, free margin share, SYMBOL_VOLUME_MAX, and SYMBOL_VOLUME_LIMIT, and it names the cap that decided. Unit tests, a tester EA, and a Python consistency check cover these decisions. In the tested runs, the budget did not reduce drawdown.

The lot size code in many MQL5 examples answers one question. How many lots lose X money if this stop loss is hit? That question is enough for an EA that holds one position on one symbol. My EAs usually trade several symbols at once, and then the one question is not enough. Before a new entry I also want to know how much money is already at risk in the open positions. I also want to know whether the free margin can carry the new trade and whether the symbol's own volume limits allow it. When the volume comes out smaller than expected, I want to know which of these checks made it smaller.

Until now the sizing in my EAs was a few lines copied into each one, and the copies drifted apart. Some of those copies multiplied the stop distance by SYMBOL_TRADE_TICK_VALUE. On the MetaQuotes-Demo server, that formula asks for 10 times the volume that OrderCalcProfit() gives on XAUUSD and XAGUSD (see the Python consistency check below). I moved the sizing into one include file so that each EA uses the same code.

Author: Ali Akbar