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

 
a1 = OrdersTotal();
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 ... ???

 
        
FAQ 04.03.2011 12:56 

Подскажите, как найти цену последнего фрактала?


sergeev: Для этого можно воспользоваться индикатором iFractals. Он возвращает значение 0, если на баре нет фрактала и значение цены фрактала если он есть. Фракталы делятся на верхние и нижние. Если вам надо получить верхние, то в функцию iFractals передается MODE_UPPER, а для нижних - MODE_LOWER. Поэтому для поиска фрактала надо пройти в цикле по барам и первое не 0 значение и будет искомым фракталом.

пример:

double frac;
for (int i=3; i<Bars; i++)
{
   frac=iFractals(Symbol(), Period(), MODE_UPPER, i); if (frac>0) break;
   frac=iFractals(Symbol(), Period(), MODE_LOWER, i); if (frac>0) break;
}
if (frac>0) Print("Цена последнего фрактала: ", frac);


пример организации отдельной функции:

//---------------------------------------------------------------   GetLastFrac
double GetLastFrac(string smb, int tf, int iB)
{
   int n=iBars(smb, tf);  double frac;
   for (int i=iB; i<n; i++)
   {
      frac=iFractals(smb, tf, MODE_UPPER, i); if (frac>0) return(frac);
      frac=iFractals(smb, tf, MODE_LOWER, i); if (frac>0) return(frac);
   }
   return(0);
}
.....
Print("Последний фрактал: ", GetLastFrac("EURUSD", 60, 3));
It was in the FAQ, I flipped through it the first few times and didn't notice.
 
Neo333:
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.

 
Neo333:
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--) {....}

 
artmedia70:

Change the direction of the order enumeration:

for (i=a1-1; i>=0; i--) {....}

Works ... but what's the logic - what difference does i++ or i-- ???
 
Zhunko:

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.

 
Neo333:
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.

 
Neo333:
Works .... but what is the logic - what difference does it make i++ or i-- ???
you've already been answered by a user
152
ilunga to this question
 
nadya:
you've already been answered by a user
152
ilunga to this question
Something told me I should have chewed it up and given a more detailed answer... :)
 
Zhunko:
... open the timetable autonomously.
The rest of the charts are "ticking". Not an option.
Reason: