Discussion of article "Orders, Positions, and Deals in MetaTrader 5" - page 2

 

Торговыми событиями считаются следующие изменения на счете:

  • debiting and charging of funds;
  • charging of commissions, swaps and taxes;
  • setting, deleting and modifying orders;
  • execution of transactions on the basis of orders;
  • opening and closing of positions;
  • changing the volume and direction of positions.

The list does not include such trading event as "modification of StopLoss and/or TakeProfit levels" of an open position(SL & TP Modification). Or is it considered as a special case of "execution of trades on the basis of orders"?

 
Yedelkin:

The list does not include such a trading event as "modification of StopLoss and/or TakeProfit levels" of an open position(SL & TP Modification). Or is it considered as a special case of "order-based trades"?

"Modification of StopLoss and/or TakeProfitlevels " at an open position (SL & TP Modification)" is closer to "setting, removing andmodifying orders".
  • setting, deleting and modifying orders;
 
Rosh:
"Modification of StopLoss and/or TakeProfit levels" at an open position(SL & TP Modification)" is closer to the

I was thinking about this question. But, in fact, when speaking about "setting, deleting and modifying orders", we are talking about setting, deleting and modifying pending orders. Modification of SL and/or TP levels of an open position is of a somewhat different nature, as the corresponding requests belong to the category of "orders of immediate execution". Or am I wrong about"immediate execution"?

 
Rosh:

The article gives an example of loading trading history for one day (one code has an example of loading history for 3 days). Yes, this is a limitation and the example is not universal. But if the reader understands this peculiarity while reading the article, he/she will be able to decide for himself/herself the question - for what interval and from what moment he/she needs to load trading history into the cache.

The reader has received the simplest examples and algorithms and can now independently apply them in the necessary event processing functions. He can independently create his own trading history base and do its initialisation and synchronisation, and so on.

An attempt to give specific recipes and functions for optimal work with trading history for all cases will require at least one more article. More precisely, not the examples themselves, but approaches to solving certain tasks. This article was aimed at understanding how trading functions work and what nuances should be paid attention to so as not to waste your own time on research.

I am sure that after reading the article, everything will be easy from here on.

Rashid, I am not belittling the usefulness of the article.

It's just that without life examples (the ones that can be applied to writing an EA) it seems quite referential.

Yes, there is useful information in it, and an understanding person will be able to use it. But an unsophisticated user will not be able to organise normal work with history after reading only this article, i.e. it will be useless to him.

 

There is such a part in the article:

"For example, here is a script that searches for the last order for the last day and displays information on it.

// --- defining the boundaries of the required trading history
   datetime end=TimeCurrent();                 // current server time
   datetime start=end-PeriodSeconds(PERIOD_D1);// set the start to 24 hours ago
//--- request the trading history for the day in the programme cache
   HistorySelect(start,end);
//--- get the number of orders in the history
   int history_orders=HistoryOrdersTotal();
//--- get the ticket of the order from the history that has the last index in the list
   ulong order_ticket=HistoryOrderGetTicket(history_orders-1);
   if(order_ticket>0) // get historical order in cache, work with it
     {
      //--- order status
      ENUM_ORDER_STATE state=(ENUM_ORDER_STATE)HistoryOrderGetInteger(order_ticket,ORDER_STATE);
      long order_magic      =HistoryOrderGetInteger(order_ticket,ORDER_MAGIC);
      long pos_ID           =HistoryOrderGetInteger(order_ticket,ORDER_POSITION_ID);
      PrintFormat("Order #%d: ORDER_MAGIC=#%d, ORDER_STATE=%d, ORDER_POSITION_ID=%d",
                  order_ticket,order_magic,EnumToString(state),pos_ID);

     }
   else              // unsuccessful attempt to get an order

     {
      PrintFormat("Total %d orders in history, failed to select an order"+
                  " with index %d. Error %d",history_orders,history_orders-1,GetLastError());
     }

The script description says that the last order is searched for, but the code itself talks about getting the ticket that has the last index in the list of historical orders:

//--- get the ticket of the order from the history that has the last index  в списке
   ulong order_ticket=HistoryOrderGetTicket(history_orders-1);
That is, it is implied that it is the ticket with the maximum index that refers to the last order. But I have not found anywhere in the materials that the last order is always guaranteed to have the maximum index in the list of historical orders. ...If, say, there is only one order in the list, there is no question. But if there are more orders in the list - can we always rely on the proposed method of finding the last order? In other words, is the last historical order always guaranteed to have the maximum index in the list of historical orders?
 

Afternoon!

1) I looked at the position properties:

POSITION_PROFIT

what is it, what is it measured in?

Example:

double profit =PositionGetDouble(POSITION_PROFIT);

result:

EURUSD position #101470723: POSITION_MAGIC=0, open pos price=1.30825, close pos price=1.30835, type=POSITION_TYPE_BUY, profit=-2061584302, comment=.

profit=-2061584302 how to understand it?

2) Can someone accurately but simply explain how to read this entry

ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);

Perhaps the PositionGetInteger(POSITION_TYPE) cis function has requested the value of a property called POSITION_TYPE for a pre-selected position, but this value is returned as an enumeration sequence number, and to represent it in a digestible form, we get this digestible value already from the ENUM_POSITION_TYPE cis enumeration into the type variable, whose type is declared as ENUM_POSITION_TYPE at the same time?

In that case, do I understand correctly that it is possible to write a certain class by myself, which in meaning will become a function, approx:

initialisation textPosition = that certain class; // in the constructor of which read into the position buffer and remember all parameters

and then use:

tekPriceOpening=tekPosition.PriceOpening;

tekDirectionPosition=tekPosition.DirectionPosition;

tekDirectionPosition=tekPosition.DirectionPosition;

tekProfitPosition=tekPosition.ProfitPosition;

Thank you!

 
bivmail:

2) Can someone explain exactly but simply how to read this entry

ENUM_POSITION_TYPE type=(ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);

The function PositionGetInteger("property identifier") returns a value of type long. If the "property identifier" is of a type other than long (e.g. the POSITION_TYPE identifier is of type ENUM_POSITION_TYPE), it is desirable to cast the value returned by the PositionGetInteger() function to a value of the required type (i.e. to a value of type ENUM_POSITION_TYPE).

In your example, the variable type of ENUM_POSITION_TYPE type is declared, to which the value of ENUM_POSITION_TYPE type is assigned, obtained as a result of explicit conversion of the value of long type to the value of ENUM_POSITION_TYPE type.

The rules of casting values of numeric types are described in MQL5 Reference Guide / Language Basics / Data Types / Type Casting / Casting Numeric Types

Документация по MQL5: Торговые функции / PositionGetInteger
Документация по MQL5: Торговые функции / PositionGetInteger
  • www.mql5.com
Торговые функции / PositionGetInteger - Документация по MQL5
 

Quote from the article: "When connection to the trade server is lost, the terminal periodically makes attempts to restore connection".

What is the frequency of attempts to restore connection?

 
Every 5 seconds.
 

Got it, thanks.