Dear Guys
I just want to know how to SELECT_BY_POS return index. I mean how to open order indexing. is older order to new order. when I open 1st order then order index = 0. then I open 2nd order then that index=1 or 2nd index = 0 and 1st order =1.
no I just want to know how indexing start oldest to new order or new to oldest.
I mean 1st order = 0, 2nd order = 1, 3rd order = 2. this way or 1st order = 3, 2nd order = 2, 3rd order = 0.
no I just want to know how indexing start oldest to new order or new to oldest.
I mean 1st order = 0, 2nd order = 1, 3rd order = 2. this way or 1st order = 3, 2nd order = 2, 3rd order = 0.
no I just want to know how indexing start oldest to new order or new to oldest.
I mean 1st order = 0, 2nd order = 1, 3rd order = 2. this way or 1st order = 3, 2nd order = 2, 3rd order = 0.
From my experience OrdersHistoryTotal select by position, 0 will return the lowest ticket number, which will usually be the oldest order.
However, if there are triggered pending orders in history, they will be positioned according to their ticket number, not the time that they were triggered.
EDIT: I wrote this back to front originally
. . . but from what I have also read it isn't guaranteed . . . so if you want the oldest or newest or them sorted then to be certain you should check.
There does seem to be some discussion in the past regarding whether (and how) the order pools are sorted. See OrderSelect() and ticket behavior - ascending/descending? and WHRoeder's code comments.
I haven't actually checked whether the order pools are sorted and how . . . I just assumed they weren't sorted (or weren't reliably sorted) and created a routine to sort them the way I wanted.
There does seem to be some discussion in the past regarding whether (and how) the order pools are sorted. See OrderSelect() and ticket behavior - ascending/descending? and WHRoeder's code comments.
I haven't actually checked whether the order pools are sorted and how . . . I just assumed they weren't sorted (or weren't reliably sorted) and created a routine to sort them the way I wanted.
![](https://c.mql5.com/mql4/forum/2013/09/yes_6.gif)
The default sort for the following Pool Position.
- MODE_TRADES =OrderOpenTime
- MODE_HISTORY =OrderCloseTime
I've never been able to reproduce the random sort error.
Anyways, if its critical then, produce your own sort.
The default sort for the following Pool Position.
- MODE_TRADES =OrderOpenTime
- MODE_HISTORY =OrderCloseTime
I've never been able to reproduce the random sort error.
Anyways, if its critical then, produce your own sort.
I put this code in a script
datetime ticket, lastticket; for(int i=OrdersHistoryTotal()-1;i>=0;i--) { OrderSelect(i,SELECT_BY_POS,MODE_HISTORY); ticket=OrderCloseTime(); if(ticket>lastticket) Print("Index number=",i,", Ticket number=",OrderTicket(),", Order Close Time is Later"); if(ticket<lastticket) Print("Index number=",i,", Ticket number=",OrderTicket(),", Order Close Time is Earlier"); lastticket=ticket; }
and the result showed that MODE_HISTORY is not ordered by close time
As already said, best to sort it and be safe.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear Guys
I just want to know how to SELECT_BY_POS return index. I mean how to open order indexing. is older order to new order. when I open 1st order then order index = 0. then I open 2nd order then that index=1 or 2nd index = 0 and 1st order =1.