Skip to content
All library documents

Capping Trade Size by a Percentage of Free Margin

Article MQL5 code base

Summary

The document presents a trading-platform routine that limits a requested order size using a configured percentage of the account’s free margin. When the requested lots exceed the calculated cap, the routine reduces them and adjusts the result to the broker’s permitted volume step.

It also checks the broker’s minimum lot size. If the calculated size falls below that minimum, it raises the order to the minimum, which can exceed the intended percentage cap. The example uses a 25% setting and divides a portion of free margin by a fixed 1,000, but it does not explain how that conversion relates to instrument-specific losses, leverage, stop distance, or actual capital at risk. This is therefore a position-sizing example, not a complete loss-risk model; its assumptions should be checked before use.

Key ideas

  • The routine compares requested lots with a size derived from a set percentage of free margin.
  • If the request is too large, it reduces the order and rounds it to the broker’s volume step.
  • A broker minimum can force the size above the calculated cap.
  • The example does not account for stop distance or explain its fixed conversion across instruments.

Tags

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