Read orders, deals and positions separately

An MT5 order is an instruction, a deal records execution, and a position reflects exposure. The MQL5 reference identifies DEAL_ENTRY_IN, OUT, INOUT and OUT_BY. The deal record also links to its originating order and to a position identifier where applicable. These relationships are more informative than grouping by symbol alone. MQL5 Reference · Deal properties ↗

A reversal changes two exposures

On a netting account, an illustrative sell of 1.5 lots against an open long of 1.0 can close the long and open a short of 0.5. A reversal entry conveys that combined effect. In a close-by workflow, OUT_BY indicates closing against an opposite position. Review the account mode and actual recorded entries before reconstructing exposure.

Reconcile the whole record

Use deal IDs to deduplicate and compare time, order, position, volume, currency and monetary fields such as profit, swap and commission. Preserve non-trade deal types separately. Test partial fills and reversals before using the result in revenue or client reporting.