OrderSelect() and ticket behavior - ascending/descending?

 

A few questions regarding ticket numbering and OrderSelect() behavior:

1. Is it guaranteed that orders opened have ascending ticket numbers? So for example - if order x was opened AFTER order y, is it guaranteed that ticket x > ticket y?

2. Regarding 1 – is this a broker specific behavior? Can this be different for different brokers?

3. When using OrderSelect( i, SELECT_BY_POS ) – for ascending i, will it select tickets by ascending ticket numbers? So for example i=0 selects the lowest ticket number… Is this guaranteed?

4. Regarding 3 – is this a broker specific behavior? Can this be different for different brokers?

 
Yes, yes, no, no.
Yes, yes, no, no.
 
Ok, so regarding 3 - internally how does MT4 decide which ticket to select for i=0,1,2...? I imagine it's not random.
 
gordon:
Ok, so regarding 3 - internally how does MT4 decide which ticket to select for i=0,1,2...? I imagine it's not random.

It seems to be based on order placement time - i.e earliest first. For example, if you place two pending orders, then the first to be placed always seems to be returned by OrderSelect(0, SELECT_BY_POS). This continues to be the case even if the first order is filled first, and its OrderOpenTime() therefore changes to after that of the second order.


(This should mean that it's the the same as selection in order of ticket number, but personally I don't have Roger's certainty that later orders are absolutely guaranteed to have later ticket numbers.)

 
but if thats true then the answer for 3 is also yes?
 
gordon:
but if thats true then the answer for 3 is also yes?

I believe so. But I've never written anything which relies on the ordering of ticket numbers, and so I've never done a full analysis of the behaviour of OrderSelect(). Personally, I'd try to avoid making any assumptions in code about ticket numbering and OrderSelect()'s behaviour. For example, if you need to track the sequence in which orders were originally placed (i.e. potentially different from sorting by OrderOpenTime()), then I'd maintain this data yourself rather than relying on ticket numbers. But I'm a very paranoid person...

 

Well, I asked a general question cause I would be happy to understand how it generally works so I can code better in the future... But specifically I asked this because I have some code that needs to know what is the oldest open order from the current open orders...

If the answer to the questions is yes then OrderSelect(0,SELECT_BY_POS) should select that order. But if no then the order could be found by a simple loop that Selects and compares OrderOpenTime() of each order...


So the question is if I use OrderSelect(0,SELECT_BY_POS) - will that grantee that I have selected the oldest open order (the order with the earliest open time)?

 
gordon:

So the question is if I use OrderSelect(0,SELECT_BY_POS) - will that grantee that I have selected the oldest open order (the order with the earliest open time)?

The answer could be either yes or no, partly depending on what you mean by open time. One of the annoyances of MT4 is that OrderOpenTime() can return either placement time or fill time. If you use pending orders then SELECT_BY_POS is definitely not guaranteed to be sorted by fill time rather than placement time.


Personally, regardless of whether you're using pending orders or not, I wouldn't rely on behaviour of OrderSelect() which hasn't been formally documented. I'd explicitly do the sorting yourself using something like the technique I described in https://www.mql5.com/en/forum/118657.

 
Guess I'll do it the long way. I hate the way there is so much undocumented stuff in MQL4... And whats documented is many times not of high quality (I imagine a translation from Russian?). I hope they do a better job in MQL5. It would make the platform and language so much more usable.
 
gordon:
Guess I'll do it the long way. I hate the way there is so much undocumented stuff in MQL4... And whats documented is many times not of high quality (I imagine a translation from Russian?). I hope they do a better job in MQL5. It would make the platform and language so much more usable.

MT5 is a huge step backwards....No Hedge etc etc.... Don't hold your breath......it's a slow DOA. The only hope is if they enthusiastically support both..... MT4 for Forex traders...and MT5 for people that want stocks and other instruments...instruments that real Forex traders have already happily abandoned FOREVER ...and want NOTHING to do with....Many Forex traders trade Forex BECAUSE of these other instruments...BECAUSE THEY WANT TO GET AS FAR AWAY FROM THEM AS POSSIBLE!!!

 
Hmmm... I haven't read much about MT5 yet, but I'm curious why u think it's a step back? From what I have read the language is object oriented, 20 times faster and comes with a real debugger (finally!). Are u talking about a step back from the perspective of platform features and abilities or is the language itself a step back?
Reason: