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
| Record | Number | What it identifies | Changes over time? |
|---|---|---|---|
| Order | Order ticket | One instruction sent to the server | No |
| Deal | Deal ticket | One execution (one fill) | No |
| Position | Position ticket | The open position right now | Can change in netting mode when a position is reversed |
| Position | Position identifier | The position across its whole life | No |
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:
| Step | Record | Ticket (invented) | Position identifier |
|---|---|---|---|
| 1. Buy 0.20 lots | Order | 500101 | 500101 |
| 1. Buy 0.20 lots | Deal (entry) | 700201 | 500101 |
| 2. Sell 0.10 lots (partial close) | Order | 500150 | 500101 |
| 2. Sell 0.10 lots | Deal (exit 1) | 700260 | 500101 |
| 3. Sell 0.10 lots (final close) | Order | 500188 | 500101 |
| 3. Sell 0.10 lots | Deal (exit 2) | 700300 | 500101 |
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:
- Positions: one row per closed position, with the position identifier, the open and close time and price, and the combined profit. This is the closest to a “trade list”.
- Orders: one row per order, including cancelled and expired pending orders that never became deals.
- Deals: one row per execution, including balance operations such as deposits and withdrawals. Entry and exit are separate rows.
- Deals and orders views may be combined in some builds, with both numbers visible.
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?
- To link entry and exit of one trade: the position identifier.
- To refer to one specific fill: the deal ticket.
- To refer to an instruction, including cancelled ones: the order ticket.
- To find the open position now: the position ticket, remembering that it can change in netting mode.
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
- Column names and menu wording differ between MetaTrader 5 builds and brokers. Check your own terminal.
- The ticket numbers in the example are invented.
- Some brokers and server types handle history differently, for example for old data. Ask your broker if numbers still do not match.
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?
Is the order ticket the same as the position ticket?
Why does one trade show several deals?
Which number should I use to match entry and exit?
Does a deal appear for a cancelled pending order?
Related guides
- A local trading journal for MT5
- P&L calendar for MT5
- Trade notes, ratings and screenshots
- Trading progress and goals
- Back up your journal and move it to a new PC
- An offline trading journal for Windows
- How to set monthly trading goals
- Import your whole MT5 history
- How to tag trades
- Trade screenshots for your journal
- All trading journal comparisons
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