CHistoryOrderInfo: missing Select(void) and Select(ulong ticket) methods??? COrderInfo has them both...

Dima Diall
127

Hello all... I finally managed to get my head around the benefit of using these 4 classes of the Standard Library for working with active/historic orders, deals and positions -- CPositionInfo, CDealInfo, COrderInfo, CHistoryOrderInfo.

Not sure if this could be a bug in the header file HistoryOrderInfo.mqh, but class CHistoryOrderInfo lacks any methods for selecting orders from history by ticket number, as opposed to COrderInfo that includes them for active pending orders. This appears to render CHistoryOrderInfo fairly useless, and requires using the built-in MQL5 function HistoryOrderSelect() -- for example, this coding pattern is not possible:

      COrderInfo        ord_info;
      CHistoryOrderInfo hst_info;

      ord_info.Select(12345);      // Works as expected to select active order by ticket
      hst_info.Select(12345);      // Compiler error: 'Select' - undeclared identifier!!!

      // Here is an ugly workaround...
      if (HistoryOrderSelect(12345))
         h_info.Ticket(12345);

      // More code to work with the selected active/historic order
      // ...
Any thoughts on this? 


Dima Diall
127
Dima Diall  

Hmmm... In the meantime, to avoid messing with the Standard Library itself, I am thinking to derive the original CHistoryOrderInfo class into my own custom one, e.g. CHistoryOrderInfoExtra that provides this lacking functionality for selection by ticket -- seems like I can easily adapt the two COrderInfo::Select() for a quick fix-up job.

#include <Trade/HistoryOrderInfo.mqh>

class CHistoryOrderInfoExtra : public CHistoryOrderInfo
{
protected:
// NB: this piece of data is inherited from parent class
// ulong             m_ticket;             // ticket of history order

public:
   bool              Select(void);
   bool              Select(const ulong ticket);
};

//+------------------------------------------------------------------+
//| Selecting an order to access                                     |
//+------------------------------------------------------------------+
bool CHistoryOrderInfoExtra::Select(void)
{
   return (HistoryOrderSelect(m_ticket));
}
//+------------------------------------------------------------------+
//| Selecting an order to access                                     |
//+------------------------------------------------------------------+
bool CHistoryOrderInfoExtra::Select(const ulong ticket)
{
   if(HistoryOrderSelect(ticket))
   {
      m_ticket = ticket;
      return (true);
   }
   m_ticket = ULONG_MAX;
//---
   return (false);
}
Alexander Martinez
3227
Dima Diall #:

Hmmm... In the meantime, to avoid messing with the Standard Library itself, I am thinking to derive the original CHistoryOrderInfo class into my own custom one, e.g. CHistoryOrderInfoExtra that provides this lacking functionality for selection by ticket -- seems like I can easily adapt the two COrderInfo::Select() for a quick fix-up job.

Welcome to the world of MetaQuotes, where you inherit the classes they built to add stuff they forgot and fix the problems (if possible) that they refuse to address.

Carl Schreiber
Moderator
13904
Carl Schreiber  

Look at the example from here: https://www.mql5.com/en/docs/trading/historyselect

On the left side you see the all functions about orders, positions and deals. You have to understand the difference of them .

Documentation on MQL5: Trade Functions / HistorySelect
Documentation on MQL5: Trade Functions / HistorySelect
  • www.mql5.com
HistorySelect - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5