Save ticket numbers

 

Is it programaticallty safe to manually keep track of ticket numbers an EA has opened in an array instead of scanning and using OrderSelect() the whole time? Are there any advantages to doing this - I think it may be faster if you have a very large order history.

Do the ticket numbers ever change?

Even if the terminal is restarted?

I am aware that I will have to scan at least once to load my tickets on EA init. I am also aware that I will need to update my array when a ticket has closed due to SL or TP.

 
rocketman99:

Is it programaticallty safe to manually keep track of ticket numbers an EA has opened in an array instead of scanning and using OrderSelect() the whole time? Are there any advantages to doing this - I think it may be faster if you have a very large order history.

Do the ticket numbers ever change?

Even if the terminal is restarted?

I am aware that I will have to scan at least once to load my tickets on EA init. I am also aware that I will need to update my array when a ticket has closed due to SL or TP.

Fair question but what you need to with ticket-number alone.?? Normally ticket-number is used to select a order and get details like SL, TP etc. So either way, you store ticket in array or not, you have to scan history to get order details, isn't it.?? The point is if you use multiple arrays to store each of the orderdetails. So bigger the order history, the bigger will be your each array.

From performance point, i think the big & more the array, the more memory it will consume while running. Got the point.??

 
dineshydv:

Fair question but what you need to with ticket-number alone.?? Normally ticket-number is used to select a order and get details like SL, TP etc. So either way, you store ticket in array or not, you have to scan history to get order details, isn't it.?? The point is if you use multiple arrays to store each of the orderdetails. So bigger the order history, the bigger will be your each array.

From performance point, i think the big & more the array, the more memory it will consume while running. Got the point.??


OrderSend() returns a ticket number. OrderSelect() can either take an index (if you loop through orders), or it can take a ticket number. See https://docs.mql4.com/trading/OrderSelect

So if I just save the ticket number issued during the OrderSend(), is this not enough info?

My question really is can I trust that the ticket number issued is unique and will never change, even if I loose connection or relogin or the broker restarts their server.

 

I already know orderselect function so you dont need to post link here. The final question remains same - what you want to achieve by storing ticket-number..?? Its just a running number and nothing else.

And regarding your question - ticket-number wont change (in real account). They serves like a unique key. But dont rely on index, its dynamic.

 
rocketman99:

My question really is can I trust that the ticket number issued is unique and will never change, even if I loose connection or relogin or the broker restarts their server.

I'm pretty sure your Order History resides on your Terminal so accessing it should be nice and quick anyway. I also think the Ticket numbers are indeed unique . . . they are an int so there are plenty left . . .
 
RaptorUK:
I'm pretty sure your Order History resides on your Terminal so accessing it should be nice and quick anyway. I also think the Ticket numbers are indeed unique . . . they are an int so there are plenty left . . .

Thanks Raptor. I guess I am being pedantic about efficiency. Lets say I have an order history of a 1000 entries. It is probably not optimal to scan through the entire list on every tick looking for a particular order. Why not just keep track of the order and hit it directly every time.
 
Be aware that some brokers modify the ticket number when a pending order becomes a market order, also when closing a partial order.
 
rocketman99:

Thanks Raptor. I guess I am being pedantic about efficiency. Lets say I have an order history of a 1000 entries. It is probably not optimal to scan through the entire list on every tick looking for a particular order. Why not just keep track of the order and hit it directly every time.
Nothing wrong with wanting better efficiency . . assuming you first have code that already works and also that in making it more efficient you don't break it. Do you need the better efficiency ?
 
sxTed:
Be aware that some brokers modify the ticket number when a pending order becomes a market order, also when closing a partial order.
I think some also change the ticket numbers when an order is held overnight . . . they don't allow swaps.
 

There are several problems you might face when handling orders within the EA without checking via OrderSelect()

Iif an order is closed by SL or TP your EA wont know that has happend.

If you part close an order the remaining part wil be assigned a new ticket number by the brokers server your EA will not know about that.

If you do an OrderSend(), OrderModify() or OrderClose() and you do not recieve the server's response for some reason ..internet glitch etc, your EA wont know if that order was actually processed or not.

 
Thanks all. It sounds like a bad idea so I won't try to manually keep track of orders.