Generate some orders.
Execute this and see what you get:
for(int i = 0; i < OrdersTotal()-1; i++){
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
Print("Number ", i, " OpenTime ", TimeToStr(OrderOpenTime(), TIME_DATE|TIME_SECONDS), " CloseTime ", TimeToStr(OrderOpenTime(), TIME_DATE|TIME_SECONDS));
}
Generate some orders.
Execute this and see what you get:
for(int i = 0; i < OrdersTotal()-1; i++){
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
Print("Number ", i, " OpenTime ", TimeToStr(OrderOpenTime(), TIME_DATE|TIME_SECONDS), " CloseTime ", TimeToStr(OrderOpenTime(), TIME_DATE|TIME_SECONDS));
}
phy,
I appreciate the instructive code you provided and the way you help us understand the interworkings of MQL4.
In this case however, after several runs of the code, I discovered that the for loop must be: for(int 1=0; i < OrdersTotal(); 1++) if you want to print all open orders, otherwise it does not print the last order to open.
If you have 4 orders open, and since "i" must be less than 4-1 (ie 3), that means "i" will stop at 2 instead of 3. Therefore the upper limit for "i' is i < OrdersTotal().
You probably meant to write the for loop operator this way: for(int i = 0; i <= OrdersTotal()-1; i++)

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I am coding an EA and have a question that I can't test without having active orders. If I use a "for" cycle starting with order pool index [0] and OrderSelect( 0,SELECT_BY_POS,MODE_TRADES).
Assuming there are multiple orders on the account, will my cycle (that starts at index 0) be starting with the most recent order on the account, or the oldest order on the account. I need to
start with the most recent order.
Any help is much appreciated, Thank you.