I use MQL4 to have a partial close of all of my orders, But I can't achieve the goal, it seemed only half of my orders will be executed and nothing happened to the other half. I want to why is it and how to achieve my partial-close-all purpose?
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.
I use MQL4 to have a partial close of all of my orders, But I can't achieve the goal, it seemed only half of my orders will be executed and nothing happened to the other half. I want to why is it and how to achieve my partial-close-all purpose?
My code is below:
int total=OrdersTotal();
for(int i=0;i<total;i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==mag && OrderComment()==comment)
{
if(OrderLots()>初始手数 && OrderLots()<MathPow(加仓倍数,level-1)*初始手数)
{
bool a=true;
while(a)
{
if(OrderClose(OrderTicket(),0.5*OrderLots(),Bid,slip,Green))
{
Print("分部平仓成功");
a=false;
}
else
{
Print("分部平仓",DoubleToStr(OrderLots()),"手失败 错误代码:",GetLastError());
a=true;
}
}
}
}
}
}