In the following MQL4 CODE, how to avoid that when there are 3 different orders that need to be modified at the same time, only the same order will be modified, and other orders cannot be modified? I know that MQL4 will only modify one order at a time, which leads to the above problems. Is there a way to record them all when there are multiple orders that need to be modified at the same time, and then no new ones will be accepted until all the orders are modified?
void Check_Trailing()
{
int orders = OrdersTotal();
datetime currentTime = TimeLocal();
bool modifyFlag = false;
if (currentTime - lastCheckTime >= OrderModifyWTs) {
for(int i = 0; i < orders; i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol() != Symbol())
continue;
double currentPrice = 0;
if (OrderType() == OP_BUY) {
currentPrice = MarketInfo(Symbol(), MODE_BID);
} elseif (OrderType() == OP_SELL) {
currentPrice = MarketInfo(Symbol(), MODE_ASK);
} else {
continue;
}
double openPrice = OrderOpenPrice();
double stopLoss = OrderStopLoss();
if (OrderType() == OP_BUY && currentPrice - openPrice >= 3 * Point && OrderMagicNumber() == BuyOrder1MagicNumber)
{
if (OrderModify(OrderTicket(), OrderOpenPrice(), stopLoss + 6 * Point, OrderTakeProfit(), 0, Green))
{
Print("Trailing stop for order ", OrderTicket(), " has been modified to ");
}
else
{
Print("Failed to modify trailing stop for order ", OrderTicket(), " Error code: ", GetLastError());
}
}
elseif (OrderType() == OP_BUY && currentPrice - openPrice >= 3 * Point && OrderMagicNumber() == BuyOrder2MagicNumber)
{
if (OrderModify(OrderTicket(), OrderOpenPrice(), stopLoss + 6 * Point, OrderTakeProfit(), 0, Green))
{
Print("Trailing stop for order ", OrderTicket(), " has been modified to ");
}
else
{
Print("Failed to modify trailing stop for order ", OrderTicket(), " Error code: ", GetLastError());
}
}
}
elseif (OrderType() == OP_BUY && currentPrice - openPrice >= 3 * Point && OrderMagicNumber() == BuyOrder3MagicNumber)
{
if (OrderModify(OrderTicket(), OrderOpenPrice(), stopLoss + 6 * Point, OrderTakeProfit(), 0, Green))
{
Print("Trailing stop for order ", OrderTicket(), " has been modified to ");
}
else
{
Print("Failed to modify trailing stop for order ", OrderTicket(), " Error code: ", GetLastError());
}
}
}
elseif (OrderType() == OP_SELL && openPrice - currentPrice >= 3 * Point && OrderMagicNumber() == SellOrder1MagicNumber)
{
if (OrderModify(OrderTicket(), OrderOpenPrice(), stopLoss - 6 * Point, OrderTakeProfit(), 0, Red))
{
Print("Trailing stop for order ", OrderTicket(), " has been modified to ");
}
else
{
Print("Failed to modify trailing stop for order ", OrderTicket(), " Error code: ", GetLastError());
}
}
}
elseif (OrderType() == OP_SELL && openPrice - currentPrice >= 3 * Point && OrderMagicNumber() == SellOrder2MagicNumber)
{
if (OrderModify(OrderTicket(), OrderOpenPrice(), stopLoss - 6 * Point, OrderTakeProfit(), 0, Red))
{
Print("Trailing stop for order ", OrderTicket(), " has been modified to ");
}
else
{
Print("Failed to modify trailing stop for order ", OrderTicket(), " Error code: ", GetLastError());
}
}
}
elseif (OrderType() == OP_SELL && openPrice - currentPrice >= 3 * Poin && OrderMagicNumber() == SellOrder3MagicNumber)
{
if (OrderModify(OrderTicket(), OrderOpenPrice(), stopLoss - 6 * Point, OrderTakeProfit(), 0, Red))
{
Print("Trailing stop for order ", OrderTicket(), " has been modified to ");
}
else
{
Print("Failed to modify trailing stop for order ", OrderTicket(), " Error code: ", GetLastError());
}
}
}
}
}
if (modifyFlag) {
lastCheckTime = currentTime;
}
}
}
In the following MQL4 CODE, how to avoid that when there are 3 different orders that need to be modified at the same time, only the same order will be modified, and other orders cannot be modified? I know that MQL4 will only modify one order at a time, which leads to the above problems. Is there a way to record them all when there are multiple orders that need to be modified at the same time, and then no new ones will be accepted until all the orders are modified?