Skip to content
All library documents

Capping Risk-Based Position Sizes by Available Margin

Article MQL5 articles

Summary

This article adds margin affordability checks to an Expert Advisor that already sizes positions from a risk percentage and an ATR-based stop. It distinguishes the planned loss if a stop is reached from the margin committed when a trade opens. Tight stops can produce larger lots for the same risk budget, while other open positions may reduce free margin; a risk-correct size can therefore be rejected or leave too little room in the account.

The proposed check estimates margin for one lot with the platform’s margin calculation, applies a configurable fraction of free margin as a cap, and rounds the resulting maximum volume down to the broker’s lot step. The EA reduces an oversized candidate or skips the trade if even the minimum lot exceeds the cap. An optional adaptive cap tightens exposure as margin conditions worsen, and the checks are gathered into a pre-trade validation stage. The article gives illustrative calculations and implementation details, but does not establish performance improvement. Its estimate is for market orders and does not fully model portfolio-wide exposure, especially when multiple or hedged positions are open.

Key ideas

  • Risk-based sizing and margin affordability are separate constraints on a trade.
  • Tightening a stop can increase lot size and margin needs without changing the risk budget.
  • A free-margin usage limit can cap the risk-sized volume, rounded down to the broker’s lot step.
  • The trade should be skipped when the affordable volume falls below the broker’s minimum lot.
  • The described margin estimate does not fully account for multiple positions or portfolio-wide exposure.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.