Hello,
I am trying to get a last order close price (most recently closed order) based on filter Magic number and Order symbol.
Code :
My code is working fine as i want but the only problem is, if my account have 10,000+ Closed Order history, this will loop through all the 10,000 closed order and this will make EA slow. How to resolve this?
And one more confusion. Should i use for loop like this for(int ClosePrice_i = 0; ClosePrice_i < OrdersHistoryTotal(); ClosePrice_i++) (or) for(int i = OrdersHistoryTotal() - 1; i >= 0; i--) ?
I am trying to get a last order close price (most recently closed order) based on filter Magic number and Order symbol.
Code :
MQL4:
double LastOrderClosePrice(int magic) { double LastOrderClosePrice_Price = 0; for(int ClosePrice_i = 0; ClosePrice_i < OrdersHistoryTotal(); ClosePrice_i++) { OrderSelect(ClosePrice_i, SELECT_BY_POS, MODE_HISTORY); if(OrderSymbol() != Symbol() || OrderMagicNumber() != magic) continue; LastOrderClosePrice_Price = OrderClosePrice(); //break; => Using break gives wrong value. Without break gives correct value } return LastOrderClosePrice_Price; }
My code is working fine as i want but the only problem is, if my account have 10,000+ Closed Order history, this will loop through all the 10,000 closed order and this will make EA slow. How to resolve this?
And one more confusion. Should i use for loop like this for(int ClosePrice_i = 0; ClosePrice_i < OrdersHistoryTotal(); ClosePrice_i++) (or) for(int i = OrdersHistoryTotal() - 1; i >= 0; i--) ?
Last edited: