Discussion of article "The Use of the MQL5 Standard Trade Class libraries in writing an Expert Advisor" - page 3

 

There are also lines in the COrderInfo class

return(FormatType(str,Type()));
...
FormatType(type,Type())
...
if(m_type==Type() && m_state==State() &&

But the Type() function is absent in the class.

 

Section 1.4 of the article provides the features of the COrderInfo class, which, judging by the description, is designed to work with active pending orders. It is suggested to do the following:"To use this class to get the properties of pending orders, we first request the total number of orders and select them by order ticket"

//Select all historical orders for the specified time period
if (HistorySelect(0,TimeCurrent()))   // all orders
   {    
     // get the total number of orders
     int o_total = OrdersTotal();
   }
But if the HistorySelect() function is designed to query"history of transactions and orders", i.e. to query historical orders, why use this function when querying the total number of active pending orders?
 
Yedelkin:

In the COrderInfo class ...

But the Type() function is absent in the class.

The same situation with CDealInfo and CPositionInfo classes
 

Can someone please explain? Here is a piece of code from the CDealInfo class:

//+------------------------------------------------------------------+
//|DealInfo.mqh |
//+------------------------------------------------------------------+
#include <Object.mqh>
#include "SymbolInfo.mqh"
//+------------------------------------------------------------------+
//| Class CDealInfo.|
//| Appointment: Class for access to history deal info. ||
//| Derives from class CObject.|
//+------------------------------------------------------------------+
class CDealInfo : public CObject
  {
   ...
public:
   ...
   //--- fast access methods to the string position properties
   string            Symbol()           const;
   ...
  };
...
//+------------------------------------------------------------------+
//| Get the property value "DEAL_SYMBOL." ||
//| INPUT: no.|
//| OUTPUT: the property value "DEAL_SYMBOL". ||
//|| REMARK: no.|
//+------------------------------------------------------------------+
string CDealInfo::Symbol() const
  {
   return(HistoryDealGetString(m_ticket,DEAL_SYMBOL));                           //stupidly return
  }
...
//+------------------------------------------------------------------+
//| Converts the deal parameters to text. ||
//| INPUT:str - receiving string,|
//| deal - pointer at the class instance. ||
//| OUTPUT: formatted string.|
//|| REMARK: no.|
//+------------------------------------------------------------------+
string CDealInfo::FormatDeal(string& str) const
  {
   string type,volume,price,date;
   CSymbolInfo symbol;                                                    
//--- set up
   symbol.Name(Symbol());
   int digits=symbol.Digits();
//--- form the description of the deal
   switch(Type())
     {
      ...
     }
//--- return the result
   return(str);
  }
...
//+------------------------------------------------------------------+

Here the function CDealInfo::FormatDeal(string& str) contains this line:

   symbol.Name(Symbol());
In turn, the Symbol() function is defined both in the CDealInfo class itself and among the standard functions of the client terminal. Which function is passed as an argument to the symbol.Name() function? By what rule?
 
Yedelkin:

Can someone please explain? Here is a piece of code from the CDealInfo class:

Here the function CDealInfo::FormatDeal(string& str) contains this line:

In turn, the Symbol() function is defined both in the CDealInfo class itself and among the standard functions of the client terminal. Which function is passed as an argument to the symbol.Name() function? By what rule?

The same rule as with the scope of variables works here. If a variable is declared under one name at the global and local levels, then inside the local scope the name will point to the local variable and outside to the global one.

It turns out that if a standard function is overloaded inside a class, the overload body will be called in the class itself and the body of the standard function will be called at the global level. The body of the overloaded function can be called at the global level through the class pointer.

 
Urain:

The same rule works here as with the scope of variables. If a variable is declared under the same name at the global and local levels, then inside the local scope the name will point to the local variable, and outside to the global one.

It turns out that if a standard function is overloaded inside a class, the overload body will be called in the class itself and the body of the standard function will be called at the global level. The body of the overloaded function can be called at the global level through the class pointer.

Thank you very much! It is clear and understandable!
 
Thank you Samuel for writing such an in-depth article. It is appreciated.
 
Nice and easy to understand
 
Very nice article! I'm using this as a reference.
 
Chapter 1.4 uses order history to describe COrderInfo, is it right?