Discussion of article "Library for easy and quick development of MetaTrader programs (part XXVIII): Closure, removal and modification of pending trading requests"

 

New article Library for easy and quick development of MetaTrader programs (part XXVIII): Closure, removal and modification of pending trading requests has been published:

This is the third article about the concept of pending requests. We are going to complete the tests of pending trading requests by creating the methods for closing positions, removing pending orders and modifying position and pending order parameters.

This is the third article about the concept of pending requests. In this article, we are going to complete the tests of the concept by creating the methods for closing positions, removing orders and modifying position stop orders and pending order parameters that can be modified.

Besides, we will slightly improve the abstract order class by adding the return of the two order and position property values — order filling and expiration types. The code of all trading methods of the basic cross-platform trading object has been slightly optimized. There is no point in dwelling on the changes. Instead, I will display a single example of one of the changed methods.

Author: Artyom Trishkin

 

Hi Artyom, is there a particular reason you allocate dynamic memory to a pointer to perform the work below?

int CTrading::GetIndexPendingRequestByOrder(const ulong ticket)
  {
   CPendingReq *req=new CPendingReq();
   if(req==NULL)
      return WRONG_VALUE;
   req.SetOrder(ticket);
   this.m_list_request.Sort(SORT_BY_PEND_REQ_TICKET);
   int index=this.m_list_request.Search(req);
   delete req;
   return index;
  }

In my humble opinion, I think that using a plain local variable would make the method simpler and get rid of superfluous pointer-handling code above.

int CTrading::GetIndexPendingRequestByOrder(const ulong ticket)
  {
   CPendingReq req;
   req.SetOrder(ticket);
   this.m_list_request.Sort(SORT_BY_PEND_REQ_TICKET);
   int index=this.m_list_request.Search(req);
   return index;
  }

I am curious to understand your reasoning to choose the former approach... maybe I am missing some best practice?

/dima

 
ddiall :

Hi Artyom, is there a particular reason you  allocate dynamic memory to a pointer to perform the work below?

In my humble opinion, I think that using a plain  local variable  would make the method simpler and get rid of superfluous pointer-handling code above.

I am curious to understand your reasoning to choose the former approach... maybe I am missing some best practice?

/dima

The Search() method works with a pointer to an object:

 int Search(
   CObject*  element       // sample 
   ) const 
 
Artyom Trishkin:

The Search() method works with a pointer to an object:

Ah right... but couldn't you invoke the method and pass the pointer of the local variable instead?

int index=this.m_list_request.Search(GetPointer(req));
 
ddiall :

Ah right... but couldn't you invoke the method and pass the pointer of the local variable instead?

You can do it in different ways ... I've done this ... :)

 
Artyom Trishkin:

You can do it in different ways ... I've done this ... :)

Cool, thanks - it was just to confirm my understanding as I am still reading the articles and studying the code ;-)
 
ddiall:
Cool, thanks - it was just to confirm my understanding as I am still reading the articles and studying the code ;-)
OK. Are you welcome :)
Reason: