Are history_orders_get() and history_deals_get() always chronologically ordered in MQL5?

 

When using the Python Integration functions history_orders_get() and history_deals_get() , I've noticed that the returned orders and deals always seem to be sorted by their execution timestamp in chronological order.

If I can rely on this ordering, it would simplify my logic and enhance the performance of my trading algorithm.

However, I haven't found anything in the MQL5 documentation that guarantees this chronological order will always be maintained.

Can anyone confirm if history_orders_get() and history_deals_get() always return orders and deals sorted by their execution timestamp in chronological order?


 
Deals and orders are sorted by ticket numbers.

For deals this is automatically indicated that they are sorted by time.

This is not the case for orders.
 
fxsaber #:
Deals and orders are sorted by ticket numbers.

For deals this is automatically indicated that they are sorted by time.

This is not the case for orders.

What I aim to achieve is to periodically retrieve any new orders added to the history since the last time I checked.

My idea involves saving the most recent execution or cancellation timestamp (referred to as 'time_done' in the Python API, which corresponds to ORDER_TIME_DONE in MQL5) with each retrieval.
Then, for the subsequent fetch, I'll filter orders in the time range starting from this saved timestamp up to the current one.
After each retrieval, I'll update and save the latest timestamp for the next round.

This approach seems viable and ensures that no order is missed.
However, it's predicated on the MT5 Server consistently adding orders to the history according to the chronological sequence of the 'time_done' field.
That's the key assumption I need to verify."

 
Trader_Patinhas #:

However, it's predicated on the MT5 Server consistently adding orders to the history according to the chronological sequence of the 'time_done' field.

That's the key assumption I need to verify."

Unfortunately, orders are not added in chronological order. You can delete an order, but it will not necessarily be at the end of the trading history.


The terminal developers are aware of this behavior and are not going to change it.

Reason: