order_calc_profit: asymmetric USD half-cent results on MT5 build 6300 / Python 5.0.6231

Could MetaQuotes clarify the rounding/normalization stages used by the MT5 Python order_calc_profit function, or identify the appropriate official technical-reporting channel?

Environment observed: terminal build 6300, MetaTrader5 Python 5.0.6231; DEMO, USD account with 2 currency decimals; XAUUSDm, calculation mode 0, contract size 100, price digits 3, Tick Size 0.001, Tick Value 0.1 USD. All calculations below use 0.01 lot.

These are saved hypothetical calculation results, not trades, fees or balance postings. The mathematical reference applies Decimal ROUND_HALF_UP only to the final signed USD PnL. A broker support statement describes final-step USD rounding with ties away from zero, but its application to this SDK path has not been established.

Eight cases differ from that exact-decimal reference by one cent:

Side Open Close Exact USD Reference USD SDK USD SDK minus reference
BUY 4000 3999.995 -0.005000 -0.01 0.0 0.01
SELL 4000 3999.995 0.005000 0.01 0.0 -0.01
BUY 4000 3999.985 -0.015000 -0.02 -0.01 0.01
SELL 4000 3999.985 0.015000 0.02 0.01 -0.01
BUY 4096 4095.995 -0.005000 -0.01 0.0 0.01
SELL 4096 4095.995 0.005000 0.01 0.0 -0.01
BUY 4096 4095.985 -0.015000 -0.02 -0.01 0.01
SELL 4096 4095.985 0.015000 0.02 0.01 -0.01

Symmetric controls (same volume/specification):

Side Open Close Exact USD Reference USD SDK USD
BUY 4000 4000.005 0.005000 0.01 0.01
SELL 4000 4000.005 -0.005000 -0.01 -0.01
BUY 4000 4000.015 0.015000 0.02 0.02
SELL 4000 4000.015 -0.015000 -0.02 -0.02

The binary64 input price differences for 4000 -> 3999.995 and 4000 -> 4000.005 have the same magnitude: 0.0050000000001091393642127513885498046875. Yet the BUY return magnitudes are 0 and 0.01. Across 48 retained controls, exact final Decimal half-up matches 40; simple binary64 arithmetic followed by final half-up matches 42. Thus ordinary input representation error alone has not explained all observations.

Minimal read-only reproduction: the caller supplies a MetaTrader5 module already initialized to a DEMO terminal. No login, order_check or trading request is included. This snippet has not been rerun to collect new samples.

from decimal import Decimal as D, ROUND_HALF_UP

def readonly_controls(mt5):
    account = mt5.account_info()
    if account is None or account.trade_mode != mt5.ACCOUNT_TRADE_MODE_DEMO:
        raise RuntimeError("DEMO required")
    assert account.currency == "USD" and account.currency_digits == 2
    spec = mt5.symbol_info("XAUUSDm")
    assert spec and spec.trade_calc_mode == 0 and spec.digits == 3
    assert spec.trade_contract_size == 100 and spec.trade_tick_size == 0.001
    for base in (D("4000"), D("4096")):
        for shift in (D("-.005"), D("-.015"), D(".005"), D(".015")):
            close = base + shift
            for action, side in ((mt5.ORDER_TYPE_BUY, 1), (mt5.ORDER_TYPE_SELL, -1)):
                current = mt5.account_info()
                if current is None or current.trade_mode != mt5.ACCOUNT_TRADE_MODE_DEMO:
                    raise RuntimeError("Account changed; stop")
                exact = (close - base) * D("100") * D(".01") * side
                reference = exact.quantize(D(".01"), rounding=ROUND_HALF_UP)
                raw = mt5.order_calc_profit(action, "XAUUSDm", .01, float(base), float(close))
                print(action, base, close, exact, reference, repr(raw))

Questions:
1. At what stage are price differences and USD amounts normalized/rounded? Is the trade direction applied before or after monetary rounding? Are the above results expected for this build/API version?
2. What documented version/build scope applies? If intermediate details are not public, can an official technical team inspect these concrete inputs?
3. Is order_calc_profit only a hypothetical estimate that may round differently from actual deal.profit and balance posting? Which final rounding rule applies to actual USD settlement?

I am not asserting a confirmed SDK defect or a settlement defect; no executed deals corresponding to these controls exist. Please distinguish an implementation explanation from an unverified numerical hypothesis.

This question is not for forum users.

Can read related threads:
https://www.mql5.com/en/forum/518384

NOTE: The Forum is mainly for users to:

  (i) exchange ideas

  (ii) discuss trading strategies, market trends, MetaTrader features and coding tips

  (iii) share views on other trading-related and market-related topics.
MetaQuotes-Demo XAUUSD — applicable contract and cost settings for October 2-9, 2026
MetaQuotes-Demo XAUUSD — applicable contract and cost settings for October 2-9, 2026
  • 2026.10.15
  • www.mql5.com
We are validating an existing private, offline XAUUSD research archive from MetaQuotes-Demo...