Selecting a certain open position to modify

Mohamed Mostafa Mohamed Sonbol  

Hello

i am new here and just learning 

there are already opened positions on mt5

Then my EA  opened several positions to buy for example using trade.Buy which is instance of CTrade

and i want to modify certain position (opened with my EA) based on ticket number,

how can i get the ticket number of open positions that was opened with my EA and not other opened positions.


thank you 

R4tna C  
max s:

Hello

i am new here and just learning 

there are already opened positions on mt5

Then my EA  opened several positions to buy for example using trade.Buy which is instance of CTrade

and i want to modify certain position (opened with my EA) based on ticket number,

how can i get the ticket number of open positions that was opened with my EA and not other opened positions.


thank you 

You need to be able to identify which positions your EA opened - usually one can set a unique magic number at the time of opening to make it easy.

Once that is known, use the Position functions - loop through the positions and select the ones you want - read all the documentation to get an idea.

The standard documentation does not seem to have examples but I wrote something similar for another query, so you can look at that to see how to construct the loop:

https://www.mql5.com/en/forum/429908#comment_41190517


https://www.mql5.com/en/docs/trading/positiongetticket

Documentation on MQL5: Trade Functions / PositionGetTicket
Documentation on MQL5: Trade Functions / PositionGetTicket
  • www.mql5.com
PositionGetTicket - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: