MT5 deal, order and position IDs: which number is which

One trade can have three orders, three deals and one position. See what each MetaTrader 5 ticket means and which number links entries to exits.

Three kinds of record, three kinds of number

MetaTrader 5 keeps three related records of what you did, and each has its own number. An order is an instruction: buy 0.10 lots now, or sell if the price reaches a level. A deal is the result of an order being executed: the fill itself, with a price, a volume, a commission and a time. A position is what you hold after one or more deals: the net exposure on a symbol. Mixing them up is the main reason traders count trades wrongly and fail to match numbers between the terminal, a report and a spreadsheet.

Each of the three has a ticket, and a fourth number, the position identifier, ties them together. This page explains what each number is, which one to use as the key when you build a journal or a script, and how the same trade looks in the three views of the History tab.

What each number identifies

RecordNumberWhat it identifiesChanges over time?
OrderOrder ticketOne instruction sent to the serverNo
DealDeal ticketOne execution (one fill)No
PositionPosition ticketThe open position right nowCan change in netting mode when a position is reversed
PositionPosition identifierThe position across its whole lifeNo

According to the MQL5 documentation and long-running forum answers by developers, the position identifier is assigned when the position opens, matches the ticket of the order that opened it, and is stamped on every order and deal that opens, changes or closes that position. That is why it is the number that links an entry deal to its exit deal.

One trade, followed through (hypothetical)

A trader sends a market order to buy 0.20 lots of gold, and later closes it in two steps. In the records it looks like this:

StepRecordTicket (invented)Position identifier
1. Buy 0.20 lotsOrder500101500101
1. Buy 0.20 lotsDeal (entry)700201500101
2. Sell 0.10 lots (partial close)Order500150500101
2. Sell 0.10 lotsDeal (exit 1)700260500101
3. Sell 0.10 lots (final close)Order500188500101
3. Sell 0.10 lotsDeal (exit 2)700300500101

There are three orders and three deals, but one position. If you count deals you will say you made three trades; if you count positions you will say one. A trading journal that records one entry per closed position, with the partial closes combined, matches how most traders think about a trade. The numbers above are invented for illustration. Real tickets are assigned by your broker’s server and look different.

The same trade in the History tab

In the terminal, open the Toolbox (Ctrl+T), go to the History tab and right-click to switch between the views. The names can vary a little by build, so check yours:

If your numbers do not match between views, the usual cause is that one view counts deals and another counts positions. See MT5 trade history not showing for date-range and view problems, and how to export MT5 trade history for getting the rows out.

Hedging and netting change what a position is

On a hedging account every entry opens its own position, so a buy and a sell on the same symbol are two positions that coexist. On a netting account there is at most one position per symbol: a second buy adds to it and a sell reduces or reverses it. In netting mode, reversing a position keeps the same position identifier but the position ticket is replaced by the ticket of the order that caused the reversal. Anything that stores the position ticket as a permanent key can therefore lose track of the position. That is the main reason developers store the identifier rather than the ticket. The full effect on your records is in MT5 hedging vs netting and your trade history.

Which number should you use as the key?

If you work with the MetaTrader 5 Python package, the same logic applies: deals carry a position identifier field, and grouping by it reunites entries and exits. A worked example is in reading MT5 history deals in Python.

Finding one trade by its number

When a broker support agent or a signal provider quotes a ticket, check which kind of number it is before you search. A deal ticket will not be found in the Positions view, and an order ticket may belong to a pending order that never filled. Search the Deals view for a deal ticket, the Orders view for an order ticket, and the Positions view for the identifier. If a trade seems to be missing entirely, work through the checks in the missing-history checklist.

What this means for your journal

A journal that stores one row per deal will overcount trades, double-count partial closes and split a single decision across several rows. A journal that stores one row per closed position, dated by the last exit, matches the way you would describe the trade to another trader. AI Trading Journal works this way: it reads your MetaTrader 5 history read-only, combines partial closes into one entry and records the net result, profit plus commission plus swap, then adds new closed trades every five minutes. You add the setup, emotion, notes and screenshots. It does not capture charts or record the intended price of an order. For the comment field that sometimes explains how a position closed, see MT5 history comments.

Limits of this guide

A worked case of one position with several closing deals is in MT5 partial close in trade history.

Frequently asked questions

What is the difference between a ticket and a position ID in MT5?
A ticket numbers one record, such as an order or a deal. The position identifier numbers the position across its whole life and is stamped on every order and deal of that position.
Is the order ticket the same as the position ticket?
Often they look the same for a simple position, because the identifier matches the ticket of the order that opened it. They are different things and can diverge, for example when a netting position is reversed.
Why does one trade show several deals?
Entries, partial closes and the final exit are separate executions, so each is its own deal even though they belong to one position.
Which number should I use to match entry and exit?
The position identifier.
Does a deal appear for a cancelled pending order?
No. A cancelled order has an order record but no deal, because nothing was executed.

Related guides

One entry per closed position, read from your MT5 history: free for 7 days

Free for 7 days, no card required. After that, a one-time $19.99 purchase. No subscription. Also on the Microsoft Store.

One-time $19.99, no monthly fee · your MT5 login never leaves your PC · trades go into your own journal on your PC, not through our servers.

Start free 7-day trial