下载MetaTrader 5

平仓认不了单,求助啊

要添加评论,请登录注册
gerlff
10
gerlff  
 在持有多个单子时候,平仓函数好像选不中该平的单子,求高手解答
开仓函数:
//---------------开仓--------------------
void MYOpen()
  {
  double  MAN;
  
  int    res;

//--- buy conditions
  if (Close[0]>MAN)
     {
      res=OrderSend(Symbol(), OP_BUY, slotA, Ask, 3, 0, 0, "Order Buy", MAGICMA, 0, Red);
      PlaySound("2open");
      return;
     }
}

平仓函数:
void YingOrLoseClose()
  {
  double  MAN;
  bool yingB=false;
  bool yingBB=false;
//+---------------
 for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
      //--- check order type 
      if(OrderType()==OP_BUY)
        {
         if(Close[0]>GetOrderOpenPriceHolding()+YPOINT) //止盈
           {
            yingB=OrderClose(OrderTicket(),slotB,Bid,3,White);
            if(yingB==true)
              {
               PlaySound("2ying");
              } 
            if(yingB==False)
              { 
              Print("OrderClose error ",GetLastError());
              }    
           }
          if(Close[0]<MAN-PPOINT)//止损
           { 
           yingBB=OrderClose(OrderTicket(),slotA,Bid,3,White);
            if(yingBB==true)
              {
               
               PlaySound("2stop");
              }
            if(yingBB==False)
              { 
               Print("OrderClose error ",GetLastError());
              }                     
           }  
         break;
        }
}
要添加评论,请登录注册