# How can I know the ticket or ID of a position?

Hi everyone!

How can I know the ticket or de ID of a position across multiple pairs? What I want to do is to implement a trailing stop based on the last position that was opened.

For example, if the last position is +50 pips, then move the stop loss to break even for that position and all the other positions should have the stop at that level.

Once it makes another +50 pips, move the stoploss of all positions +50. Its not a trailing stop with a distance of +50 pips constantly.

PS

I'd go through all open positions and remember that with the highest ticket number. Should be the most recent. If you're not sure then check the opentime. MQL4 OrderOpenTime(), MQL5 PositionGetInteger(POSITION_TIME).

ppsev:

Hi everyone!

How can I know the ticket or de ID of a position across multiple pairs? What I want to do is to implement a trailing stop based on the last position that was opened.

For example, if the last position is +50 pips, then move the stop loss to break even for that position and all the other positions should have the stop at that level.

Once it makes another +50 pips, move the stoploss of all positions +50. Its not a trailing stop with a distance of +50 pips constantly.

PS

When you use

`PositionsTotal()`

it returns the number of opened positions. The oldest position has index 0. Let's imagine you have 6 positions opened

```int num_pos = PositionsTotal();
ulong pos_ticket = PositionGetTicket( num_pos - 1 );```

In this case pos_ticket gives you the ID of the most recent position. This is assuming you have only have positions opened for one symbol

Fernando Morales:

When you use

it returns the number of opened positions. The oldest position has index 0. Let's imagine you have 6 positions opened

In this case pos_ticket gives you the ID of the most recent position. This is assuming you have only have positions opened for one symbol

Thank you Fernando. How would you do it if you have open positions in more than one pair?

PD :do you speak Spanish?

Is the ID of the Position (CPositionInfo::Indentifier) the same as the ticket number ?