下载MetaTrader 5

求助 移动止损问题

要添加评论,请登录注册
zhiqiang_2016
25
zhiqiang_2016  
下面程序调用不到
下面空单程序调用不到 OrderStopLoss(); 的值,OrderStopLoss()的值一直是0。价格修改是成功的,实盘也目测修改价格成功,但移动止损一直是Ask价格多少移动止损价格(NormalizeDouble(MarketInfo(Symbol(),MODE_ASK)+UsePoint*移动止损,Digits);)也跟随是多少,价格降,止损价格也降,价格升,止损价格也升。永远无法平仓。止损达不到价格递增或递减效果。各位朋友有没遇到过这个问题?检查问题,是因为OrderStopLoss()得值一直是0,取不到更新后价格。有遇到的朋友请教一下了。

void SellTrailingStop(string argsellSymblol,int MagicNumbersell)
  {
   for(int j=0;j<=OrdersTotal();j++)
     {
      if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()!=MagicNumbersell || OrderSymbol()!=argsellSymblol) continue;

      if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES)==true)
        {
         if(OrderMagicNumber()==MagicNumbersell && OrderSymbol()==argsellSymblol && OrderType()==OP_SELL && OrderComment()==OrdersellMartin)
           {
            ModifyTicket=OrderTicket();
            ModifyPrice=OrderOpenPrice();
            Modifyprofit=OrderTakeProfit();
            Symbollots=Orderlots("sell",MagicNumbersell);
            Symbolspread=MarketInfo(Symbol(),MODE_SPREAD);
            Commis=Symbolspread*Symbollots;
            Orderstoploss=OrderStopLoss();
            ModifyPrice=OrderOpenPrice();
            Profitpoint=UsePoint*(移动止损+Commis);
            Sellask=MarketInfo(Symbol(),MODE_ASK);
            Min_Dist=MarketInfo(Symbol(),MODE_STOPLEVEL);  // Min. distance
            if(Profitpoint<Min_Dist) Profitpoint=Min_Dist;
            Stoplossprice=NormalizeDouble(MarketInfo(Symbol(),MODE_ASK)+UsePoint*移动止损,Digits);
 
            if(移动止损>0)
              {
               if(ModifyPrice-Sellask>Profitpoint)
                 {
                 if((Orderstoploss>Stoplossprice) || (Orderstoploss==0)) 
                   {
                     TicketMod=false;

                     while(TicketMod==false)
                       {
                        if(OrderModifyPreChecked(ModifyTicket,ModifyPrice,Stoplossprice,Modifyprofit,0))
                           TicketMod=OrderModify(ModifyTicket,ModifyPrice,Stoplossprice,Modifyprofit,0,Red);//                       
                        else break;

                        if(TicketMod==false)
                          {
                           error=GetLastError();

                           if((error==129) || (error==136) || (error==141) || (error==4108) || (error==0) || (error==1))
                             {
                              Sleep(1000*(60*Timemin));
                              RefreshRates();
                             }
                           else
                             {
                              ErrorMessage=StringConcatenate("空单移动止损故障:",iGetErrorInfo(GetLastError()));
                              printf("空单移动止损故障:"+iGetErrorInfo(GetLastError()));
                              break;
                             }
                          }
                        else
                          {
                           Ticketclose=StringConcatenate("空单移动止损成功,新的止损价:"+DoubleToStr(Stoplossprice,Digits));
                           break;
                          }
                       }
                     }
                 }
              }
           }
        }
     }
  }
要添加评论,请登录注册