[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 240

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
for (i = 0; i < a1; i++)
{
OrderSelect(i,SELECT_BY_POS);
OrderDelete(OrderTicket());
}
Here's a simple script like this should delete all pending orders, but it deletes exactly half of the orders ... ???
a1 = OrdersTotal();
for (i = 0; i < a1; i++)
{
OrderSelect(i,SELECT_BY_POS);
OrderDelete(OrderTicket();
}
This simple script should delete all pending orders but it deletes exactly half of them ... ???
Let's say there were 10 orders.
Here you have deleted half (zero to five)
now you want to select the sixth one... and there are only 5 left. There is an error and there is nothing to delete. It's the same with the others.
a1 = OrdersTotal();
for (i = 0; i < a1; i++)
{
OrderSelect(i,SELECT_BY_POS);
OrderDelete(OrderTicket();
}
This simple script should delete all pending orders, but it deletes exactly half of the orders ... ???
Change the direction of the order search:
for (i=a1-1; i>=0; i--) {....}
Change the direction of the order enumeration:
for (i=a1-1; i>=0; i--) {....}
1. Have you checked?
Report: It helped, but it seems to be glitchy.
First terminal. Removed all charts and symbols, added 7 dollar symbols, added charts. All with reloads.
Stretched the ticker to 3/4 of the screen. Filled the first 6, the 7th got up to 5 squares.
After next restart not all filled completely, distribution is almost random - the lower symbol in list, the less cells it gets.
The second terminal. I had 7 yen pairs on it. Removed extra characters, restarted - they fill much deeper, but the depth of filling turned out to be distributed randomly.
I incline to the fact that this is a bug because of the small cache - it's just not enough for everyone, while the distribution is either random or "first come, first served".
In any case, for one currency the method works. Summary: recipe to the fact :) Thanks.
It works ... But what is the logic - what difference does i++ or i-- ???
You have already been told what the reason is. It's not about i++ or i--, it's about which end of the list you start to delete orders from - the beginning of the list (as you did) or the end of the list (as you need to do in this case).
To understand what happens when orders are deleted, you need to know and understand how the orders are stored in the array.
When you delete the first order first (it is indexed by i=0), the indexes of all orders are shifted in the array - the first order becomes null, the second order becomes first, the third one becomes second and so on. This is why all orders are not completely deleted - in fact, when i becomes 6, the sixth order is shifted to the fifth position in the array of orders and the order is simply not selected by index 6.
When you delete orders from the end of the list, the shift will not happen - the first order has a zero position in the list, and it will continue to have it. The 10th order had position 9, it was deleted, then the 9th order, which has a position 8 in the list is deleted, and so on, until the first order with a position zero in the array of orders.
Works .... but what is the logic - what difference does it make i++ or i-- ???
you've already been answered by a user
... open the timetable autonomously.