for(i=1; i <=OrdersTotal(); i++) Orders in this list are numbered from zero to OrdersTotal()-1 inclusive (let Artem Trishkin excuse me, just shortened the wait for nys2000).
Vladimir: for(i=1; i <=OrdersTotal(); i++) Orders in this list are numbered from zero to OrdersTotal()-1 inclusive (let Artem Trishkin excuse me, just shortened the wait for nys2000).
Thanks, but the numbering of orders from 0 to OrdersTotal()-1 is taken into account in OrderSelect(i-1,...)
At the moment the function is started, two Buy positions are open. The function prints the presence of two orders twice: Passage 1, Passage 2.
We remove the comments and run the function again. It vigorously takes down one buy order, declares "Passage #1" and leaves the loop. The message "Passage #2" does not appear.
What is the magic?
1. i=1, we calculated the orders ... checked condition 1<= 2 ? yes. Selected and closed the order.
2. i++ (i=2)
3. OrdersTotal()=1 <---------- by closing the order inside the loop actually changed the condition to exit the loop
4. 2<=1 ? no <----------- here your "magic" and accordingly exit from the loop
void CloseAllOrders()
{
bool Ans;
int total=OrdersTotal();
for(int i=1; i <=total; i++)
{
Print("Проход № ", i);
if (OrderSelect(i-1,SELECT_BY_POS)==true)
{
if (OrderSymbol() != Symbol())
continue;
if (OrderType()==0)
{
// Ans=OrderClose(OrderTicket(),OrderLots(), NormalizeDouble(Bid,Digits),25);
}
if (OrderType()==1)
{
// Ans=OrderClose(OrderTicket(),OrderLots(), NormalizeDouble(Ask,Digits),25);
}
}
}
return;
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Could you be more specific?
start from scratch
Could you be more specific?
start from scratch
These are two equivalent options. If for (i=1...) then OrderSelect(i-1,...), if for (i=0,...) - OrderSelect(i,...)
for(i=1; i <=OrdersTotal(); i++) Orders in this list are numbered from zero to OrdersTotal()-1 inclusive (let Artem Trishkin excuse me, just shortened the wait for nys2000).
Thanks, but the numbering of orders from 0 to OrdersTotal()-1 is taken into account in OrderSelect(i-1,...)
Thank you, but the numbering of orders from 0 to OrdersTotal()-1 is accounted for in OrderSelect(i-1,...)
Do the reverse order of the search ...
Here's a simple code like this:
At the moment the function is started, two Buy positions are open. The function prints the presence of two orders twice: Passage 1, Passage 2.
We remove the comments and run the function again. It vigorously takes down one buy order, declares "Passage #1" and leaves the loop. The message "Passage #2" does not appear.
What is the magic?
1. i=1, we calculated the orders ... checked condition 1<= 2 ? yes. Selected and closed the order.
2. i++ (i=2)
3. OrdersTotal()=1 <---------- by closing the order inside the loop actually changed the condition to exit the loop
4. 2<=1 ? no <----------- here your "magic" and accordingly exit from the loop
why is there an additionalCHART_WINDOW_HANDLE chart ID, what purpose does it serve?
why is there an additionalCHART_WINDOW_HANDLE chart ID, what purpose does it serve?
Error during execution
Result: random number (certainly not 3)