how can Orders, Positions and Deals be linked together?

 
Hi,

how can Orders, Positions and Deals be linked together? 

Is there a way to link them apart from the magic number?

Best Reguards,
ZeroCafeine.
 
The position ID (deals + positions)
 
Lorentzos Roussos #:
The position ID (deals + positions)

tsk you  Lorentzos Roussos, I didn't know about it, so I'm going to look into it further.


my need : 
when I press a button Key_B, which places multiple orders, multiple SL, TP, ....
What kind of trick is it to link all future orders, positions, partial exits, .... until their end of life, to be managed by my EA (tick per tick), and not interfere with others that will be opened 2 h later or that were opened 2 h before?

can be a structure variable that will be updated until this position set is closed, Can be a datetime variable at the moment I click on Key_B

if (id == CHARTEVENT_KEYDOWN){
   if (lparam == KEY_B) {
      // From here on, a value to link everything together in a struct variable
      if (my condition){
         trade.BuyLimit(
      }

}
Lorentzos Roussos
Lorentzos Roussos
  • 2023.11.17
  • www.mql5.com
Trader's profile
 
 if (id == CHARTEVENT_KEYDOWN ){
   if (lparam == KEY_B) {
       // From here on, a value to link everything together in a struct variable
       if (my condition){
         trade.SetExpertMagicNumber(12345 + TimeHour());
         trade.BuyLimit(
      }

}
 
ZeroCafeine: Orders, Positions and Deals

They are linked by their respective tickets and especially overall by their Position Identifier ticket which is usually the same as the Order ticket that first created the position.

All subsequent orders and deals that affect that position, will reference that unique identifier that is assigned to all orders and deals executed for the entire lifetime of the position.

ENUM_POSITION_PROPERTY_INTEGER

POSITION_IDENTIFIER

Position identifier is a unique number assigned to each re-opened position. It does not change throughout its life cycle and corresponds to the ticket of an order used to open a position.

Position identifier is specified in each order (ORDER_POSITION_ID) and deal (DEAL_POSITION_ID) used to open, modify, or close it. Use this property to search for orders and deals related to the position.

When reversing a position in netting mode (using a single in/out trade), POSITION_IDENTIFIER does not change. However, POSITION_TICKET is replaced with the ticket of the order that led to the reversal. Position reversal is not provided in hedging mode.

long


ENUM_ORDER_PROPERTY_INTEGER

ORDER_POSITION_ID

Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The identifier of exactly this position is set to the executed order at this moment.

long

ENUM_DEAL_PROPERTY_INTEGER

DEAL_POSITION_ID

Identifier of a position, in the opening, modification or closing of which this deal took part. Each position has a unique identifier that is assigned to all deals executed for the symbol during the entire lifetime of the position.

long

Also, please read the following ...

Articles

Orders, Positions and Deals in MetaTrader 5

MetaQuotes, 2011.02.01 16:13

Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.

 
Thank you all for your answers

What do you think of storing all the information about a trade until it closes in a structure variable?

Do you have any other ideas? I'm still a beginner with MQL5 code.
 
ZeroCafeine #:
Thank you all for your answers

What do you think of storing all the information about a trade until it closes in a structure variable?

Do you have any other ideas? I'm still a beginner with MQL5 code.

Certainly possible - you need to be clear what you want to store and why, how you will use it and how frequently it will be refreshed ((some values may be out of date with each tick)

Also if your EA is re-started, how will you get this data back into the structure?

Have a good think about the purpose and design before doing it - you may find it better/simpler to just read the data you need in real-time (less chance of inconsistency). In fact I recommend starting with developing the methods/functions to retrieve the data you need (it will improve your MQL5 skills), and then decide whether it is worth keeping it all in a struct or just read it when needed.

 

@ R4tna C thank you for your reply and your interest 

As far as the values I need are concerned, I'm still groping my way slowly towards the values I need now and in the future. 

I'm starting to do some tests on structure variables, there are so many things to see and check to have perfect code.

When I say perfect, I just mean no mistakes and knowing how to manage and detect them.

And yes, once these variable structures have been saved in a tablet, I'd like to be able to refresh them if necessary, and I'd like to check them every time I tick, and be able to refresh them if necessary.

As for the case where my expert advisor reboots, I've already thought about it, and I seem to have seen the possibility of saving a table in hard copy, so that when the expert advisor reboots, he can retrieve it and continue working with the same table.

And I can see that you're Indian. I don't know how old you are, but I grew up with this film by Shashi Kapoor 😍 Aa Gale Lag Jaa (1973) 

R4tna C
R4tna C
  • www.mql5.com
Trader's profile
 
ZeroCafeine #:

@ R4tna C thank you for your reply and your interest 

As far as the values I need are concerned, I'm still groping my way slowly towards the values I need now and in the future. 

I'm starting to do some tests on structure variables, there are so many things to see and check to have perfect code.

When I say perfect, I just mean no mistakes and knowing how to manage and detect them.

And yes, once these variable structures have been saved in a tablet, I'd like to be able to refresh them if necessary, and I'd like to check them every time I tick, and be able to refresh them if necessary.

As for the case where my expert advisor reboots, I've already thought about it, and I seem to have seen the possibility of saving a table in hard copy, so that when the expert advisor reboots, he can retrieve it and continue working with the same table.

And I can see that you're Indian. I don't know how old you are, but I grew up with this film by Shashi Kapoor 😍 Aa Gale Lag Jaa (1973) 

Sound like you have a good plan

And yes I am Indian and am intrigued to see the Bollywood reference - reciprocally I have spent time in France (I love the cuisine) and even studied some French as an undergrad :)

 

I'm trying to programs it, but after one week or programming and learning, I stopped a little, I bought one key bord I can tell the name because or moderation, it's will help me when I will use for get some ideas for my EA,

And you are welcome in the north of France 😊

Reason: