Download MetaTrader 5

Confused about the selection of my orders, How do you achieve partial close orders?

To add comments, please log in or register
Zhihuan Xue
271
Zhihuan Xue  

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;

                    } 

                  }

               }

            }

         }

      } 

To add comments, please log in or register