In this article
After this article, you can
- Link deals to orders and the shared position without guessing the profit owner.
- Reconcile realised, unrealised and cost totals under an explicit allocation convention.
Terms at hand: Expert Advisor (EA) · Lot (position unit) · Commission
On a netting account, two robots and manual orders can change one shared position. Its result does not automatically identify each robot’s result. Reconstruct the executions and their relationships, then choose an explicit analytical allocation convention. The example below produces different EA outcomes under two conventions while the account’s combined result stays the same. This allocation is for analysis; it does not replace broker history or establish tax accounting treatment.
Why does a magic number not split the shared position?
MT5 netting maintains one position per symbol, whose quantity can change through subsequent fills. One order can also produce several deals, the records of execution. These distinctions are described in the platform’s basic principles. Different program names do not create separate portfolios inside a shared account.
DEAL_MAGIC identifies the execution’s magic number; DEAL_REASON describes its source or cause. They are different properties. Deal documentation also provides the order number, position identifier and timestamp. Magic zero alone is insufficient evidence of a manual decision. Preserve related records and the agreed mapping between program names and identifiers.
A manual exit can reduce exposure previously built by both A and B. The closing deal’s label does not tell you which earlier quantity you will regard as closed. That requires a declared analytical rule. Our EA guide addresses basic position selection; this article reconstructs one shared position’s history rather than creating a separate account for each program.
How do you connect a deal, order and position without guessing?
Store numbers as identifiers, not quantities for calculation. Connect DEAL_ORDER to its order and DEAL_POSITION_ID to the position cycle. POSITION_IDENTIFIER links the history; the current POSITION_TICKET can change through server service operations. Preserve the symbol, direction, quantity, fill price and timestamp for each actual execution.
HistorySelectByPosition selects order and deal history using the position identifier. Check that retrieval succeeded and the export covers the intended records. A list visible in one terminal window may not contain everything required for your analysis. Do not assign a missing entry to an EA solely from a closing comment. Preserve the original record before adding interpretations.
Include commission, fees, financing and result in account currency. Separate balance operations from buy and sell executions. For a split order, record the actual partial quantities and their prices; requested quantity cannot replace filled quantity. The MQL5 article develops execution-event handling and identifiers. Here, the input is a reconciled history rather than an order-submission instruction.
How can one account produce two different EA results?
Own model: two purchases and two manual exits
Assume a fictional linear EUR/USD contract of 100,000 EUR per lot, a USD account and no starting position. Every price below is a fill: purchases at the assumed Ask, sales at Bid. Four deals execute fully in the stated order. Each costs 1 USD commission; fees and swap are zero. Do not subtract the spread already reflected in the fill prices again.
| Deal / order | Source | Execution | Position afterwards |
|---|---|---|---|
| 7001 / 5001 | EA A | Buy 0.10 at 1.1000 | Long 0.10 |
| 7002 / 5002 | EA B | Buy 0.10 at 1.1020 | Long 0.20 |
| 7003 / 5003 | Manual exit | Sell 0.10 at 1.1010 | Long 0.10 |
| 7004 / 5004 | Manual exit | Sell 0.10 at 1.1030 | No position |
The shared purchase average after the second fill is 1.1010. Under this model the first reduction realises 0 USD of price P/L and the second 20 USD. After four commissions: 20 − 4 = 16 USD net. This reconciles the complete closed cycle; it is not an observed live-account result. The values are supplied assumptions rather than market data.
Analytical FIFO closes the oldest quantity first. Allocate manual exit 7003 to A: 10,000 × (1.1010 − 1.1000) = 10 USD. Allocate exit 7004 to B: 10,000 × (1.1030 − 1.1020) = 10 USD. Assign each EA its entry commission and the exit commission for its quantity. A receives 8 USD and B receives 8 USD.
Analytical LIFO closes the newest quantity first. B receives −10 USD of price P/L from 7003, while A receives 30 USD from 7004. After costs, B has −12 USD and A has 28 USD, again totalling 16 USD. FIFO and LIFO are our analytical conventions here, not a statement about MT5 server accounting or a universal tax rule. Do not silently change conventions when evaluating a robot.
Same account total, different allocations
Why does analytical realised P/L differ after the first exit?
After 7003, assume the current Bid is 1.1010. The model’s shared net position has 0 USD realised and 0 USD unrealised price P/L. Analytical FIFO realises 10 USD for A, but B’s remaining quantity has an unrealised loss of 10 USD. Together, 10 − 10 = 0 USD. Comparing analytical realised results alone with the server’s realised field is incorrect while the position is still open.
After three fills, commission totals 3 USD. Both representations therefore have a combined result of −3 USD at this price. Once 7004 closes the cycle, unrealised P/L disappears and the total allocation is 16 USD. Our floating versus realised P/L article explains these measures. Matching totals does not select the more appropriate convention for your analytical purpose.
Real histories may contain partial fills, reversals, corrections or separately posted charges. When a record is missing, leave the affected allocation unresolved and state why. Do not invent an opening price or instruction source to force reconciliation. Use a consistent convention across cycles when comparing strategies; label any change as a change in analytical method. Account controls and each robot’s limits still apply to the actual shared exposure.
What to do before evaluating two robots?
- Select a completed cycle for one symbol and preserve its original export. Link deals to orders and the position identifier. Reconcile actual quantities and all charges. Do not open a new live trade solely to manufacture an example for this analysis.
- Declare the quantity and cost allocation convention before calculating robot results. Label execution sources separately from the analytical owners of quantities. Leave missing information unresolved instead of treating the closing magic number as a complete account of earlier entries.
- Reconcile a closed cycle’s combined result with account history. For an open cycle, combine realised and unrealised P/L at the same price. Preserve both views in your trading journal. Allocation analyses behaviour; it does not establish future profitability.
Check your understanding
One short exercise
About 2 min · you can try again
After 7003, FIFO shows +10 USD realised, −10 USD unrealised and 3 USD commission. What is the combined result?
- +7 USD.
- −3 USD.
- 0 USD.
Check the answer and explanation
−3 USD.
Correct: 10 − 10 − 3 = −3 USD. It matches the shared position’s zero price P/L minus three commissions.
Frequently asked
Does the closing magic number identify the EA that earned the profit?
It is insufficient for that conclusion. An execution label helps investigate the instruction source, but a manual reduction may affect a position built by several EAs. First link actual deals to orders and the shared position identifier, then reconstruct entry quantities. Assigning an exit quantity to A or B requires an explicit analytical convention. Do not relabel a manual exit as an EA instruction. Keep instruction source and analytical quantity owner in separate columns, together with the cost allocation method.
Is the example’s FIFO a broker accounting or tax rule?
No. FIFO and LIFO are used only to demonstrate two explicit analytical quantity-allocation conventions. They do not describe two alternative MT5 server accounting methods or a universal tax rule. Preserve original account history independently of the additional worksheet. Choose and disclose one convention for comparing EAs; consult the applicable records and jurisdiction-specific rules for reporting obligations. Both variants totalling 16 USD does not make every allocation appropriate for every purpose. The analytical split is an interpretation of supplied fills, not a replacement accounting record.
Why does realised P/L differ from the server after the first exit?
In the model after deal 7003, the shared position average is 1.1010 and the exit uses that price, so realised price P/L is zero. FIFO assigns the exit to A’s older quantity and shows 10 USD realised profit. B’s remaining quantity simultaneously has an unrealised loss of 10 USD at 1.1010. Combined price P/L remains zero; after three commissions it is minus 3 USD. Compare realised plus unrealised results at the same valuation, rather than the closed component alone.
Can a missing entry be reconstructed from an exit comment?
A comment alone cannot justify inventing a missing fill, its price or its instruction source. Leave that allocation unresolved and state why. Check the retrieved history range, order and position-identifier links, and actual quantities of partial executions. Reconcile charges and balance operations separately. An analysis that forces agreement by inserting a hypothetical entry may look precise while relying on unknown data. Recording the gap is more useful than a complete-looking table with unsupported profit attribution to an EA.
Sources & bibliography
-
MetaQuotes Ltd MetaTrader 5 Help — Basic Principles · Order, deal and position distinctions; one order may have multiple deals. Netting has one position per symbol. www.metatrader5.com ↗
-
MetaQuotes Ltd MQL5 Reference — Deal Properties · DEAL_ORDER, DEAL_POSITION_ID, DEAL_MAGIC, DEAL_REASON, entry type, volume, price and cost fields. www.mql5.com ↗
-
MetaQuotes Ltd MQL5 Reference — Position Properties · POSITION_IDENTIFIER over the position lifetime and its order/deal links; POSITION_TICKET can change. www.mql5.com ↗
-
MetaQuotes Ltd MQL5 Reference — HistorySelectByPosition · Select order and deal history by position identifier and check the success result. www.mql5.com ↗
