It is sometimes necessary to find the opening time of the last position (chronologically) counting only positions with the given magic number and type.
The function below returns the timestamp of the opening time of the last position with the given magic number and type (or -1 to count all position types).
int lastOpenTime(int magic,int type) { int max=0; for(int i=0;i<OrdersTotal();i++) { if(OrderSelect(i,SELECT_BY_POS)) { if(OrderMagicNumber()==magic) { if(OrderType()==type || type<0) { if(OrderOpenTime()>max) { max=MathMax(OrderOpenTime(),max); } } } } } return(max); }