@Sparrow I just worked on a bug, reported in another topic (https://fxdreema.com/forum/topic/16239/for-each-closed-position-block-is-not-working), and the problem was exactly that Open Time for closed positions didn't work properly. I think this is fixed now. Sorry that it took few days, I worked on some JavaScript things these days.
I see you are interested in MQL5 a little bit, so I can tell you what was the problem. I have these custom MQL4-like function in MQL5, one of which is OrderOpenTime().
This function has some if in it, because it can work with positions, closed positions or pending orders. When it works with closed positions, there is a variable type that equals to 3, so we end up in ... else if (type == 3) .... The code there is like this:
ulong positionId = HistoryDealGetInteger(OrderTicket(), DEAL_POSITION_ID);
HistorySelectByPosition(positionId); // <<< THIS WAS NOT HERE, I ADDED IT TODAY
ulong ticket = HistoryDealGetTicket(0);
time = (datetime)HistoryDealGetInteger(ticket, DEAL_TIME);
HistoryTradesTotalReset();
Note my THIS WAS NOT HERE, I ADDED IT TODAY comment there, this is the code that was missing and causing the bug.
OrderTicket() would be the ticket of a deal, selected by "For each Closed Position", but this is a deal that is OUT, it's the final closing deal. We want the open time, and to get this information we want to get the first IN deal from this same position. To do this we need to get this DEAL_POSITION_ID number, then to use HistorySelectByPosition() and from there to get that first IN deal.
But some days ago, when worked to fix some other problems, I forgot to put HistorySelectByPosition() in this particular function, or I deleted it by mistake. There is one similar function OrderOpenPrice() and there I had HistorySelectByPosition(). I knew that both functions are the same when it comes to loading these deals, and these few rows of code should be exactly the same in both functions, but somehow this one row of code went missing in OrderOpenPrice().