how to get the time to open a closed trade

 
hello everyone
I want to get the time to open a closed trade. I took help from artificial intelligence and it suggested this program line.


datetime openTime = HistoryDealGetInteger(lastDealTicket, DEAL_ENTRY_TIME);


But DEAL_ENTRY_TIME does not exist in mql5. You may help. thank you
 
ghs296:
hello everyone
I want to get the time to open a closed trade. I took help from artificial intelligence and it suggested this program line.


datetime openTime = HistoryDealGetInteger(lastDealTicket, DEAL_ENTRY_TIME);


But DEAL_ENTRY_TIME does not exist in mql5. You may help. thank you
DEAL_TIME

Use the documentation, it's giving the correct info
 
Documentation on MQL5: Trade Functions / HistoryDealGetInteger
Documentation on MQL5: Trade Functions / HistoryDealGetInteger
  • www.mql5.com
Returns the requested property of a deal. The deal property must be of the datetime, int type. There are 2 variants of the function. 1. Immediately...
 
Conor Mcnamara #:

I see a code example also for this:

https://www.mql5.com/en/docs/trading/historydealgetinteger

Thank you for your attention, but I saw this document and DEAL_TIME is the closing time of the deal and not the opening time of the deal.
 
ghs296 #:
Thank you for your attention, but I saw this document and DEAL_TIME is the closing time of the deal and not the opening time of the deal.

A deal is only dealing with the closing time. So you don't work with deals then. You need to record the time when a position is executed and save TimeCurrent() in a variable.

if(tradeSignal && !finishedTrade){
        makeBuyPosition...
        positionOpenTime = TimeCurrent();
        finishedTrade = true;
}


now reset "finishdTrade" flag back to false inside a deal condition (or in another way)


better approach might be to use POSITION_TIME

for (int i = PositionsTotal() - 1; i >= 0; i--){

     
datetime positionOpenTime = PositionGetInteger(POSITION_TIME);
                                 
}
 
Conor Mcnamara #:

A deal is only dealing with the closing time. So you don't work with deals then. You need to record the time when a position is executed and save TimeCurrent() in a variable.


better approach might be to use POSITION_TIME

Thanks a lot