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.

Thank you in advance for your advices!

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.

Thank you in advance for your advices!

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 ?

Answered here: https://www.mql5.com/de/docs/constants/tradingconstants/positionproperties

Dokumentation zu MQL5: Konstanten, Enumerationen und Strukturen / Handelskonstanten / Eigenschaften der Positionen
Dokumentation zu MQL5: Konstanten, Enumerationen und Strukturen / Handelskonstanten / Eigenschaften der Positionen
  • www.mql5.com
Das Ticket der Position. Das ist eine einmalige Nummer, die jeder neu eröffneten Position zugewiesen wird. In der Regel entspricht sie dem Ticket der Order, mit der die Position eröffnet wurde, außer den Fällen, wenn das Ticket infolge Operationen auf dem Server geändert wurde. Z.B. Anrechnung von Swaps durch eine erneute Eröffnung einer...
 
Same problem, anyone has the answer? I Know how to get the last position opened but I cannot get this last position when you have more than one pair trading.