You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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;
}
}
}
}
}
}