- Make it as a habit to count down! Otherwise if you e.g. close the first order of the list your index moves on to 2 but the second order is now the first and you'll miss it:
for(int positionnumber_of_trades-1; position>=0; position--){...
- After this code line you have to select:
if ( !OrderSelect(position) ) continue; // or print the errorJust look in the reference: place the cursor on e.g. OrderSelect() and press F1. Search there for examples, there are plenty for to copy and paste :)
Carl Schreiber:
I get your point. However, for this specific scenario, I want to use OrderModify() on the orders starting with the first order to the last. There is a separate function to close the orders where I have used count down.
- Make it as a habit to count down! Otherwise if you e.g. close the first order of the list your index moves on to 2 but the second order is now the first and you'll miss it:
- After this code line you have to select:
Just look in the reference: place the cursor on e.g. OrderSelect() and press F1. Search there for examples, there are plenty for to copy and paste :)
Then assign the ticket numbers (or the timestamp of the opening) of all open positions to an integer or datetime array and sort this array and the access the the open position according to the place in the array.
Carl Schreiber:
Then assign the ticket numbers (or the timestamp of the opening) of all open positions to an integer or datetime array and sort this array and the access the the open position according to the place in the array.
So in other words the order at position 0 is not automatically the first order that was opened? This is the clarification that I need. My orders are opened at least two seconds apart, after a certain condition is met.
Then assign the ticket numbers (or the timestamp of the opening) of all open positions to an integer or datetime array and sort this array and the access the the open position according to the place in the array.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi, I am still trying to understand MQl4, so my question may be basic. My EA has ability of opening upto 10 orders, and I need to place a trailing stop to all trades depending on the order in which they were opened. Looking at topics like https://www.mql5.com/en/forum/191264 , I note that the orders are not always ordered from 0-(n-1) where n is the total number of orders. How can I access these orders starting from the first to the last say in a loop?
Why can't this code below work?