1. Can you find the earliest open position in the loop and return it to the ticket?
I can't imagine how it would be in the code), but somehow I was able to add to the EA removing pending orders, I'm not good at code, just a little bit.
7Konstantin7: I can't imagine how it will be in the code) but by some miracle I was able to add removal of pending orders to the EA, I'm not good at codes, only a little.
Just take it and see how it closes in a loop
1:
int i, total = OrdersTotal(); bool rez;
for(i = total-1; i >= 0; i--)
{
if(OrderSelect(i, SELECT_BY_POS) && другие нужные условия)
{
if(OrderType() < 2)
rez = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 40);
if(OrderType() > 1)
rez = OrderDelete(OrderTicket());
}
}
2:
//Всё тоже самое только поменяй направление циклаfor(i = 0; i < total; i++)
Then you will understand in what order the orders are closed. I cannot say for sure because I have not checked it. I don't need it. But this is another issue, it has been discussed here more than once and I don't want to repeat it all over again.
then you'll know in which order the orders close. I can't say, because I haven't checked it. I do not need it. But this is another topic, it has been discussed here many times and I don't want to repeat it all.
Then you'll know in what order the orders close. Can't say because I haven't checked. I do not need it. But this is another issue, it has been discussed here many times and I have no desire to repeat it all.
Thanks, already solved the problem.
artmedia70:
I thought they'd send me to the john) Thanks for the help.
Hello all, I already asked a similar question on page 711, unfortunately no one has responded, maybe now someone...
I am facing a problem with closing counter orders on a five digit order. The point is that I need to close, say, 20 orders in buy and 33 in sell when the total profit is reached. And I want to close 20 buy orders and 20 sell orders using function OrderCloseBy(), and close the remaining 13 sell orders using function OrderClose().
If we have a fixed spread at 4 digits, we will not have any problems with closing the spread and we also save the spread when using the function OrderCloseBy(). If we have a 5-digit spread, the spread is floating and that is why, I think, orders are not closed when total profit is reached and the log says OrderCloseBy(). At the same time, if we run it in the tester, all is closed normally.
Orders in one direction, when the total profit is reached, are closed without any problems.
Who has encountered such a problem, and what are the options for solving it?
I will give you the function to close the orders.
Also, does the OrderCloseBy() function even work on a five-digit order.
//-----------------------------------------------------------------------// функция подсчета открытых ордеров//-----------------------------------------------------------------------void OrderOpen()
{
Orders_BUY=0; Orders_SELL=0;
for(int a=0; a<=OrdersTotal(); a++)
{
if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES) == true && OrderType()==OP_BUY && OrderMagicNumber() == Magic) Orders_BUY=Orders_BUY+1;
if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES) == true && OrderType()==OP_SELL && OrderMagicNumber() == Magic) Orders_SELL=Orders_SELL+1;
//if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES) && OrderType()==OP_BUY) Orders_BUY=Orders_BUY+1;//if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES) && OrderType()==OP_SELL) Orders_SELL=Orders_SELL+1;
ProfitAll=ProfitAll+OrderProfit()+OrderSwap()+OrderCommission();
}
}
//-----------------------------------------------------------------------// функция закрытия ордеров сначала разнонаправленных//-----------------------------------------------------------------------void ClosePos()
{
int ticket_1=0, ticket_2=0;
for (int a=0; a<=OrdersTotal(); a++)
{
if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES) == true)
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) // проверка по символу и магику
{
if(OrderType() == OP_BUY) ticket_1 = OrderTicket();
if(OrderType() == OP_SELL) ticket_2= OrderTicket();
}
}
}
if(ticket_1 != 0 && ticket_2 != 0) { // если найдены разнонаправленные ордера
res = OrderCloseBy(ticket_1,ticket_2,clrRed); } // закроем ихif(ticket_1 == 0 && ticket_2 != 0) { CloseOrder_by_type(OP_SELL,Symbol()); }
if(ticket_1 != 0 && ticket_2 == 0) { CloseOrder_by_type(OP_BUY,Symbol()); }
}
//---- Закрытие ордера по типу и комментарию ----//void CloseOrder_by_type(int type, string sym)
{
for(int k= OrdersTotal()-1;k>=0;k--)
{
if(OrderSelect(k,SELECT_BY_POS,MODE_TRADES)==true)
{
if(type == OrderType() && sym==OrderSymbol()&& OrderMagicNumber()==Magic)
if(OrderType()<=1){ res = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),350);}
else { res = OrderDelete(OrderTicket());}
if(!res)
Print("Ошибка закрытия ордера. Код ошибки=",GetLastError());
elsePrint("ордер успешно закрыт.");
}
}
}
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.
1. Can you find the earliest open position in the loop and return it to the ticket?
I can't imagine how it will be in the code) but by some miracle I was able to add removal of pending orders to the EA, I'm not good at codes, only a little.
Just take it and see how it closes in a loop
1:
2:
Then you will understand in what order the orders are closed. I cannot say for sure because I have not checked it. I don't need it. But this is another issue, it has been discussed here more than once and I don't want to repeat it all over again.Just take it and see how it closes in a loop
1:
2:
then you'll know in which order the orders close. I can't say, because I haven't checked it. I do not need it. But this is another topic, it has been discussed here many times and I don't want to repeat it all.We've already sorted it out in private...
Well, I don't read your private messages... and I don't know what's going on.
Yeah, he doesn't read... Where have my slippers gone?!?!! ;)
Remember what Ioann Vassilievich listed that he took, and Shpak didn't take... So I'm your slippers.
Bye. I'm going to bed.
Remember what Ioann Vassilievich listed that he took, and Shpak didn't take... So I'm your slippers.
Goodbye. I'm going to bed.
Just take it and see how it closes in a loop
1:
2:
Then you'll know in what order the orders close. Can't say because I haven't checked. I do not need it. But this is another issue, it has been discussed here many times and I have no desire to repeat it all.Thanks, already solved the problem.
I thought they'd send me to the john) Thanks for the help.
Hello all, I already asked a similar question on page 711, unfortunately no one has responded, maybe now someone...
I am facing a problem with closing counter orders on a five digit order. The point is that I need to close, say, 20 orders in buy and 33 in sell when the total profit is reached. And I want to close 20 buy orders and 20 sell orders using function OrderCloseBy(), and close the remaining 13 sell orders using function OrderClose().
If we have a fixed spread at 4 digits, we will not have any problems with closing the spread and we also save the spread when using the function OrderCloseBy(). If we have a 5-digit spread, the spread is floating and that is why, I think, orders are not closed when total profit is reached and the log says OrderCloseBy(). At the same time, if we run it in the tester, all is closed normally.
Orders in one direction, when the total profit is reached, are closed without any problems.
Who has encountered such a problem, and what are the options for solving it?
I will give you the function to close the orders.
Also, does the OrderCloseBy() function even work on a five-digit order.