I have searched in many places for an analogue of function : OrderCloseTime() . Such a function does not exist in МQ5. I share my way to get the closing time of an open position in MQ5. I use in the expert advisor a simple loop for a specified number of open positions: / and first make static var /
......
static long Close_Time_buy ; ......... .......... double GetLastSL_buy = 0; for(int i = 0; i < PositionsTotal(); i++) { if(m_position.SelectByIndex(i)) { if(m_position.Symbol() == _Symbol) { if(m_position.PositionType() == POSITION_TYPE_BUY) { if(m_position.Magic() == Magic_number) { count_buy_orders++; GetLastSL_buy = PositionGetDouble(POSITION_SL); ///// or GetLastTP_buy = PositionGetDouble(POSITION_TP); /////// } } } } } if( GetLastSL_buy != 0) { Close_Time_buy = TimeNow;}
.................
When closing the position, with SL or TP, the time of this action is counted and stored in the static variable. You can reset it whenever you want in your code.
The same is done for short position.
I hope this can be of help to many expert advisor developers.
Watch for my new products: https://www.mql5.com/en/users/esebg
Good luck to all traders.