Folks, help is needed. The function has to close half of the orders necessarily starting with the oldest one. In the first case, the orders are closed one by one for some reason, and in the second, they start closing in the wrong order.
void CloseHalfOrders (int otype)// ф-ция закрытия половины ордеров сетки
{
int count = 0; double CTbuy = CountTrades(OP_BUY); double CTsell = CountTrades(OP_SELL);
for (int i = 0; i<=OrdersTotal;i++)
{
if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
{
if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType() == otype)
{
if (otype == OP_BUY)
{
if (count<CTbuy/2 && CTbuy>3 )
OrderClose(OrderTicket(),OrderLots(),Bid,0,Black);
count++;
Sleep(1000);
}
elseif (otype == OP_SELL)
{
if (count<CTsell/2 && CTsell>3)
OrderClose(OrderTicket(),OrderLots(),Ask,0,Black);
count++;
Sleep(1000);
}
}
}
}
}
Hi, I've searched Kim's, but I can't find anything that lets me know: Which order (pending) opened the position from? From a limit order or a stop order?
I tried to compare prices of the last order opened
Folks, help is needed. The function should close half of the orders necessarily starting with the oldest one. In the first case, the orders are closed one by one for some reason, and in the second, they start closing in the wrong order.
There was a question like this, how to close orders starting with the oldest one, a couple of pages later there is an answer and the correct code.
Hi, I searched Kim's, but I can't find anything that lets me know: Which order (pending) opened the position from? From a limit order or a stop order?
I tried to compare prices of the last order opened
with a position opened on it but the whole logic is broken. Maybe there is something more suitable? Thanks!
Boris. Try writing in the commentary of the orders - limit to limit, stop to stop. Then from these comments of open positions you will know what the legs have grown from. Only partial closing of these comments will erase them. Maybe something else can kill the comments. Only deleted positions are saved in the history. The ones that worked aren't there. You have to go through... you figure out what you have to go through...
artmedia70: Boris. Try writing in the commentary of the orders - limit to limit, stop to stop. Then from these comments of open positions you will know what the legs have grown from. Only partial closing of these comments will erase them. Maybe something else can kill the comments. Only deleted positions are saved in the history. The ones that worked aren't there. You have to go through... You can't figure out what you have to go through...
Thank you, Artem! So I "twisted", and something is wrong. And comments and magicians do not want to attract the attention of DC. I need it only for the next move, as in chess! Everything is closed in its entirety by the conditions. I'm trying and panting, maybe I'll finish it! Happy New Year, Artem!
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.
Folks, help is needed. The function has to close half of the orders necessarily starting with the oldest one. In the first case, the orders are closed one by one for some reason, and in the second, they start closing in the wrong order.
So I need an integer...
MathRound
so this is rounding, the number does not become int, it remains double
so this is rounding, the number does not become int, but remains double
So? Is there a fundamental difference between 1 and 1.0 for calculations? Of course the format is double, but the value is integer.
An especially perverted variant then: DoubleToStr and then StringToInteger
Please tell me how to remove the warning in the new compiler
possible loss of data due to type conversion
Thank you, so no pre-warning, it's already eating my eye)
Hi, I've searched Kim's, but I can't find anything that lets me know: Which order (pending) opened the position from? From a limit order or a stop order?
I tried to compare prices of the last order opened
with a position opened on it but the whole logic is broken. Maybe there is something more suitable? Thanks!
Folks, help is needed. The function should close half of the orders necessarily starting with the oldest one. In the first case, the orders are closed one by one for some reason, and in the second, they start closing in the wrong order.
There was a question like this, how to close orders starting with the oldest one, a couple of pages later there is an answer and the correct code.
https://www.mql5.com/ru/forum/145455/page406
Hi, I searched Kim's, but I can't find anything that lets me know: Which order (pending) opened the position from? From a limit order or a stop order?
I tried to compare prices of the last order opened
with a position opened on it but the whole logic is broken. Maybe there is something more suitable? Thanks!
Boris. Try writing in the commentary of the orders - limit to limit, stop to stop. Then from these comments of open positions you will know what the legs have grown from. Only partial closing of these comments will erase them. Maybe something else can kill the comments. Only deleted positions are saved in the history. The ones that worked aren't there. You have to go through... You can't figure out what you have to go through...