Learning and writing together in MQL5 - page 42

 
Thank you!
 
Well, apparently not...
 

Can you tell me why this script does not delete all orders, there are 3 pending orders in total in the terminal, but the script only deletes 2.

for(i = 0; i < OrdersTotal(); i++)
     {
     ticket = OrderGetTicket(i);
     Alert(ticket," ",i);
     if(ticket > 0)
       {
       trade.OrderDelete(ticket);
       }
     }
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров - Документация по MQL5
 
asasusa: Can you tell me why this script does not delete all orders, there are 3 pending orders in total in the terminal, but the script deletes only 2
Because of the condition.
i < OrdersTotal(); 
You have Alerts there - see what it shows.
 
Yedelkin:
Because of the condition You have Alert there - see what it shows.
What's wrong with this condition, can you elaborate?
 
int total=OrdersTotal();

for(i = total; i > 0; i--)
     {
     ticket = OrderGetTicket(i);
     Alert(ticket," ",i);
     if(ticket > 0)
       {
       trade.OrderDelete(ticket);
       }
     }
 
sovetnikmaker: What's wrong with this condition, can you tell us more about it?

Look at the description of the for statement and try to answer two questions:

1) how often is the condition I specified checked in the loop;

2) what values is returned by the function OrdersTotal() at each check of the condition "i < OrdersTotal()" (taking into account that the body of for statement itself contains code for deleting an order).

 
Who can I contact about converting an MT4 indicator for MT5?
 
iTC:
Who can I contact about converting MT4 indicator for MT5?
There is a link to the "Jobs" service at the top - go there
 
ilunga:
There's a link at the top to the "Jobs" service - that's where you go.
Thank you. (chuckles)
Reason: