Volume-tiered margin: OrderCalcMargin does apply the tiers if you pass the total volume (fixes "not enough money" in Market validation)
Two clarifications to my post, to be precise:
1. The "four validation runs" were my own local reproductions in the Strategy Tester (same symbols and timeframes as the Market check, 1 minute OHLC, factory inputs). I have not submitted the EA to the real validator yet, so I can't confirm that part from MetaQuotes' side.
2. In thread 486768 the "can't be read from MQL5" point was one reply's assessment, not an official conclusion. What I can confirm is only what I measured on MetaQuotes-Demo: OrderCalcMargin with the total volume returns the tiered value.
In thread 486768 the conclusion was that the volume-dependent margin from build 4150 can't be read from MQL5. I ran into the same thing while preparing an EA for the Market and found that it can be handled with the terminal's own calculation, so here is what worked for me.
My EA places several pending stop orders and checked each one with OrderCalcMargin before sending. My own validation-style runs (EURUSD H1, 2024, $10k, 1:100, MetaQuotes-Demo) still produced hundreds of "not enough money" errors when several stops triggered on the same bar. The journal showed the margin rising by roughly 2.7-3x the expected amount per fill.
The EURUSD specification on MetaQuotes-Demo shows floating margin by volume: 1x up to 3 lots, 2x from 3 to 5 lots, 3x above 5 lots. A per-order OrderCalcMargin only sees that order's volume.
But OrderCalcMargin does use the tiers when you pass a larger volume. On the same account: 1.00 lot = 1,103.74, 8.00 lots = 18,489.76 (not 8 x 1,103.74). So instead of rebuilding the tier formula by hand, I calculate the incremental margin:
extra = OrderCalcMargin(open volume + pending volume + new lots) - OrderCalcMargin(open volume + pending volume)
and size the order so that this extra margin fits into free margin (I use 70%). I also delete pending orders that no longer fit if free margin shrinks. After that, all four validation runs (EURUSD H1, XAUUSD D1, GBPUSD M30, EURUSD M1) passed with zero errors.
One limitation: this treats all volume on the symbol as one block. If a broker nets hedged positions or tiers each direction separately, the result is conservative rather than exact.