OrderSelect(1,SELECT_BY_POS,MODE_HISTORY) - returns order in the middle of the history, Build 482

 

Hello, I use "MT4, Build 482", today I found that function OrderSelect(1,SELECT_BY_POS,MODE_HISTORY) does not return the first order from the history, but returns order from the middle of the history.

OrderSelect(1,SELECT_BY_POS,MODE_HISTORY);
Print("First Order #= ",OrderTicket());

The Result is:
2013.04.26 15:51:06 test USDCHF,M30: First Order #= 178555092

But result must be : 178532001

 I would appreciate it very much if you could clarify if this is a bug or I am expecting too much  ?

Closed Transactions:
TicketOpen TimeTypeSizeItemPriceS / LT / PClose TimePriceCommissionTaxesSwapProfit
1785306572013.04.26 13:11balanceDeposit3 000.00
1785320012013.04.26 13:17buy0.01usdchf0.943850.000000.943672013.04.26 17:230.943670.000.000.00-0.19
1785320242013.04.26 15:03buy0.01usdchf0.944400.000000.943672013.04.26 17:230.943670.000.000.00-0.77
1785320262013.04.26 13:17buy stop0.01usdchf0.945180.000000.946672013.04.26 15:420.94089cancelled
1785454052013.04.26 14:20sell0.03usdchf0.943420.000000.940652013.04.26 15:420.940650.000.000.008.83
1785454662013.04.26 15:27sell0.03usdchf0.943080.000000.940652013.04.26 15:420.940650.000.000.007.75
1785454692013.04.26 15:29sell0.03usdchf0.942930.000000.940652013.04.26 15:420.940650.000.000.007.27
1785454722013.04.26 15:30sell0.03usdchf0.942770.000000.940652013.04.26 15:420.940650.000.000.006.76
1785454752013.04.26 15:30sell0.03usdchf0.942570.000000.940652013.04.26 15:420.940650.000.000.006.12
1785454772013.04.26 15:30sell0.03usdchf0.942320.000000.940652013.04.26 15:420.940650.000.000.005.33
1785454802013.04.26 15:30sell0.03usdchf0.942010.000000.940652013.04.26 15:420.940650.000.000.004.34
1785454832013.04.26 15:30sell0.03usdchf0.941570.000000.940652013.04.26 15:420.940650.000.000.002.93
1785549502013.04.26 15:03buy stop0.03usdchf0.944520.000000.946882013.04.26 15:360.94167cancelled
1785549542013.04.26 15:03buy stop0.03usdchf0.944640.000000.946882013.04.26 15:360.94167cancelled
1785549592013.04.26 15:03buy stop0.03usdchf0.944770.000000.946882013.04.26 15:360.94167cancelled
1785549612013.04.26 15:04buy stop0.03usdchf0.944930.000000.946882013.04.26 15:360.94167cancelled
1785549752013.04.26 15:04buy stop0.03usdchf0.945110.000000.946882013.04.26 15:360.94167cancelled
1785550652013.04.26 15:04buy stop0.03usdchf0.945340.000000.946882013.04.26 15:360.94166cancelled
1785550812013.04.26 15:04buy stop0.03usdchf0.945630.000000.946882013.04.26 15:360.94167cancelled
1785550922013.04.26 15:04buy stop0.03usdchf0.946040.000000.946882013.04.26 15:360.94167cancelled
1785621422013.04.26 15:27sell0.03usdchf0.943090.000000.940572013.04.26 15:420.940570.000.000.008.04
1785622682013.04.26 15:29sell0.03usdchf0.942900.000000.940572013.04.26 15:420.940570.000.000.007.43
1785622712013.04.26 15:30sell0.03usdchf0.942780.000000.940572013.04.26 15:420.940570.000.000.007.05
1785622752013.04.26 15:30sell0.03usdchf0.942650.000000.940572013.04.26 15:420.940570.000.000.006.63
1785622792013.04.26 15:30sell0.03usdchf0.942490.000000.940572013.04.26 15:420.940570.000.000.006.12
1785622852013.04.26 15:30sell0.03usdchf0.942310.000000.940572013.04.26 15:420.940570.000.000.005.55
1785622902013.04.26 15:30sell0.03usdchf0.942090.000000.940572013.04.26 15:420.940570.000.000.004.85
1785622932013.04.26 15:30sell0.03usdchf0.941810.000000.940572013.04.26 15:420.940570.000.000.003.96
1785622962013.04.26 15:30sell0.03usdchf0.941400.000000.940572013.04.26 15:420.940570.000.000.002.65
1785718342013.04.26 15:48buy0.01usdchf0.941220.000000.943672013.04.26 17:230.943670.000.000.002.60
1785718382013.04.26 15:59buy0.01usdchf0.941700.000000.943672013.04.26 17:230.943670.000.000.002.09
1785718392013.04.26 16:03buy0.01usdchf0.942360.000000.943672013.04.26 17:230.943670.000.000.001.39
1785720082013.04.26 15:42sell0.03usdchf0.940260.000000.939302013.04.26 17:120.943430.000.000.00-10.08
1785721162013.04.26 15:43sell0.03usdchf0.940230.000000.939302013.04.26 17:120.943410.000.000.00-10.11
1785721272013.04.26 15:43sell0.03usdchf0.940200.000000.939302013.04.26 17:120.943440.000.000.00-10.30
1785721292013.04.26 15:42sell stop0.03usdchf0.940160.000000.939302013.04.26 16:030.94234cancelled
1785721312013.04.26 15:42sell stop0.03usdchf0.940120.000000.939302013.04.26 16:030.94230cancelled
1785721332013.04.26 15:42sell stop0.03usdchf0.940070.000000.939302013.04.26 16:030.94223cancelled
1785721432013.04.26 15:42sell stop0.03usdchf0.940010.000000.939302013.04.26 16:030.94215cancelled
1785721482013.04.26 15:42sell stop0.03usdchf0.939940.000000.939302013.04.26 16:030.94216cancelled
1785721572013.04.26 15:42sell stop0.03usdchf0.939850.000000.939302013.04.26 16:010.94209cancelled
1785721592013.04.26 15:42sell stop0.03usdchf0.939720.000000.939302013.04.26 16:010.94190cancelled
1785741952013.04.26 15:47sell0.03usdchf0.940830.000000.938672013.04.26 17:120.943430.000.000.00-8.27
1785753162013.04.26 15:50sell0.01usdchf0.941220.000000.939232013.04.26 17:230.943950.000.000.00-2.89
1785753192013.04.26 15:50sell0.03usdchf0.941120.000000.939232013.04.26 17:120.943430.000.000.00-7.35
0.000.000.0057.73
Closed P/L:57.73

 

I output ticket number of 3 orders, but it did not became more clear ...

OrderSelect(1,SELECT_BY_POS,MODE_HISTORY);
Print("First Order #= ",OrderTicket());
OrderSelect(2,SELECT_BY_POS,MODE_HISTORY);
Print("Second Order #= ",OrderTicket());
OrderSelect(3,SELECT_BY_POS,MODE_HISTORY);
Print("Third Order #= ",OrderTicket());

2013.04.26 15:59:16 test USDCHF,M30: Third Order #= 178555065
2013.04.26 15:59:16 test USDCHF,M30: Second Order #= 178555081
2013.04.26 15:59:16 test USDCHF,M30: First Order #= 178555092

 

 

index  0 - is a deposite. 

OrderSelect(0,SELECT_BY_POS,MODE_HISTORY); 

Print("0 Order #= ",OrderTicket());

2013.04.26 16:32:29 test USDCHF,M30: 0 Order #= 178530657 

 

 
 
 
winters:  OrderSelect(1,SELECT_BY_POS,MODE_HISTORY) does not return the first order from the history, but returns order from the middle of the history.
Did you allow ALL_History within your History_Filter?
 

Hi,

This is a history for 3 hours of trading, lodgement + result.

It looks like orders in the history are ordered by their close time. In this case such behaviour is normal.

Thank you 

 

... today I found that function OrderSelect(1,SELECT_BY_POS,MODE_HISTORY) does not return the first order from the history, but returns order from the middle of the history.

There is a possibility that the order of entries in history is not reliable (i.e., not sorted by Open Time).  See here and here.  So, you may need to manually sort the entries in history by OrderOpenTime() to the achieve the solution you are looking for. 

 
winters: I found that function OrderSelect(1,SELECT_BY_POS,MODE_HISTORY) does not return the first order from the history,

Of course it doesn't. It never did. Position ZERO is the first in the list.

If you want the earliest closed order, sort the list: Order History sort by closing date - MQL4 forum

Reason: