Stop-based sizing limits intended trade loss; it does not ensure that an account has sufficient free margin. A separate margin reserve prevents an EA from consuming its entire estimated capacity when several strategies share an account. The reserve is an operational policy, not a measure of maximum loss.

Worked example

Assume current free margin of 3000 in the account currency, with a required reserve of 1000. The estimated new-order margin budget is 2000. An estimate of 1200 leaves 1800 and passes; 2000 leaves exactly 1000; 2400 leaves only 600 and must be skipped. These are hypothetical estimates, not leverage recommendations.

How to Apply a Free-Margin Reserve Before MT5 EA Entries
A 1000 reserve leaves 2000 available for estimated new-order margin.

Use OrderCalcMargin before constructing the request

The excerpt belongs in the OnTick entry branch after calculating plannedLots, validating volume increments and checking the entry signal. It estimates margin for a buy at current ask; a sell estimate should use the corresponding order type and bid. OrderCalcMargin computes an estimate without considering existing open positions or pending orders, so portfolio and netting effects can differ.

// OnTick entry branch, before sending a BUY request
MqlTick tick;
if (!SymbolInfoTick(_Symbol, tick)) return;
double margin = 0.0;
if (!OrderCalcMargin(ORDER_TYPE_BUY, _Symbol,
                     plannedLots, tick.ask, margin))
    return;
double free = AccountInfoDouble(ACCOUNT_MARGIN_FREE);
if (free - margin < 1000.0) return;
// Build MqlTradeRequest; use OrderCheck before OrderSend.

Use OrderCheck on the actual request for additional server-side preflight information and inspect its return code, projected margin and free margin. A successful check does not guarantee a subsequent fill. Inspect OrderSend's result retcode and reconcile actual execution. If multiple EAs are operating concurrently, a locally observed margin snapshot is not an atomic reservation.

Testing and safeguards

  • Test zero/negative budget and exact boundary values, and log calculation errors rather than treating them as zero margin.
  • Re-evaluate after partial fills, leverage changes, price movement or other strategies opening positions.
  • Compare netting and hedging accounts; margin offsets can vary by broker and symbol.
  • Test with broker demo settings as well as Strategy Tester assumptions. Reserve cash separately from stop-loss risk and account drawdown limits.

Official reference: OrderCalcMargin.

This hypothetical teaching excerpt has not been compiled or backtested here. Trading involves risk of loss; simulated results do not guarantee future performance.

To adapt this free strategy idea to your trading rules, contact us about Custom MT5 strategy Development Services.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.