Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1032

 
Artyom Trishkin:

This is the time of the trade.

I do not understand.
Duration?
Or when we close an order, is that the time of the trade?
And how do I filter it out, I am only interested in the time of setting orders?
 
Roman Kutemov:
I do not understand.
Duration?
Or when we have closed an order, is that the time of the trade?
And how do I filter, I am only interested in the order times?

Not the duration, but the time of transaction.

There are no orders in the transaction list. There are two history lists in the terminal - the list of orders and the list of deals. These are the ones to look for exactly what is needed.

Read the help:

Документация по MQL5: Торговые функции / HistorySelect
Документация по MQL5: Торговые функции / HistorySelect
  • www.mql5.com
Функция HistorySelect() создает в mql5-программе список ордеров и список сделок для дальнейшего обращения к элементам списка посредством соответствующих функций. Размер списка сделок можно узнать с помощью функции HistoryDealsTotal(), размер списка ордеров в истории можно получить с HistoryOrdersTotal(). Перебор элементов списка ордеров лучше...
 
Roman Kutemov:
I do not understand.
Duration?
Or when we close an order, is that the time of the trade?
And how do I filter it out, I am only interested in the order times?
A closed position has at least two orders and two trades. They are the ones which characterise the position. First an order and a trade to open the position, then an order and a trade to close the position. If an order in the form of a pending order may "live" for some time until a deal is executed, then a deal has no such "lifetime" at all.
 
Alexey Viktorov:
A closed position has at least two orders and two trades. It is these that characterise the position. First an order and a trade to open the position, then an order and a trade to close the position. If an order in the form of a pending order can "live" for some time until a deal is executed, then a deal has no such "lifetime" at all.
OK, then how do we determine the time to open a position that is already in history?
 
Roman Kutemov:
OK, then how do we determine the time of opening a position that is already in the history?

By the transaction property of the ENUM_DEAL_ENTRY enumeration

DEAL_ENTRY_IN

Market entry

DEAL_ENTRY_OUT

Market exit

DEAL_ENTRY_INOUT

U-turn

DEAL_ENTRY_OUT_BY

Close counter position

Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства сделок
Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства сделок
  • www.mql5.com
Сделка является отражением факта совершения торговой операции на основании ордера, содержащего торговый приказ. Каждая сделка описывается свойствами, позволяющими получить информацию о ней. Для чтения значений свойств используются функции вида Идентификатор позиции, в открытии, изменении или закрытии которой участвовала эта сделка. Каждая...
 
Alexey Viktorov:

By the transaction property of the ENUM_DEAL_ENTRY enumeration

DEAL_ENTRY_IN

Market entry

DEAL_ENTRY_OUT

Market exit

DEAL_ENTRY_INOUT

U-turn

DEAL_ENTRY_OUT_BY

Close counter position

There may be many entries for one position - will you give us the information bit by bit?

Find the first trade of the DEAL_ENTRY_IN position.

 
Roman Kutemov:
Okay, then how do you determine the time of opening a position that is already in history?

Read the help - it's all there, and sometimes with examples.

Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства сделок
Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства сделок
  • www.mql5.com
Сделка является отражением факта совершения торговой операции на основании ордера, содержащего торговый приказ. Каждая сделка описывается свойствами, позволяющими получить информацию о ней. Для чтения значений свойств используются функции вида Идентификатор позиции, в открытии, изменении или закрытии которой участвовала эта сделка. Каждая...
 
Roman Kutemov:
Ok, then how to determine the opening time of a position that is already in history?

Two options

Forum on trading, automated trading systems and testing trading strategies

OrderCloseTime Expert Advisor MQL5

fxsaber, 2018.07.06 00:49

#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006

void LastTimeMQL4( datetime &OpenTime, datetime &CloseTime )
{
  for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)  
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && (OrderType() <= OP_SELL))
    {
      OpenTime = OrderOpenTime();
      CloseTime = OrderCloseTime();
      
      break;
    }
}

void LastTimeMQL5( datetime &OpenTime, datetime &CloseTime )
{
  if (HistorySelect(0, INT_MAX))
  {
    for (int i = HistoryDealsTotal() - 1; i >= 0; i--)
    {
      const ulong Ticket = HistoryDealGetTicket(i);
  
      if (HistoryDealGetInteger(Ticket, DEAL_ENTRY) == DEAL_ENTRY_OUT)
      {
        CloseTime = (datetime)HistoryDealGetInteger(Ticket, DEAL_TIME);

        if (HistorySelectByPosition(HistoryDealGetInteger(Ticket, DEAL_POSITION_ID)))
          OpenTime = (datetime)HistoryDealGetInteger(HistoryDealGetTicket(0), DEAL_TIME);
          
        break;
      }
    }
  }
}
The second option is slower but supports netting.
 
Artyom Trishkin:

There can be many entries for one position - are you just going to keep telling me bit by bit?

Find the first trade of the DEAL_ENTRY_IN position.

Artem, when you ask such questions, it is 99% that it is written for the forex market and 90% that for the account hadge. Why from the beginning to complicate life to the beginner?
 
Alexey Viktorov:
Artyom, when you ask such questions, it is 99% that it is written for the forex market and 90% that it is for the hadge account. Why to complicate a beginner's life in the beginning?
Yes, yes. There is no need to complicate life)).
After mt4, it's hard to get into it at all.
Reason: