上传ea,自动检测出现这样的问题

 

我在MT5上测试是没有这样的问题,怎么解决呀?谢谢!

 

提示手数无效,你代码中要对品种的最小手数,最大手数做个验证。

 
可以试试把单量规范一下!
 
Ziheng Zhuang:

提示手数无效,你代码中要对品种的最小手数,最大手数做个验证。

您好! 我还是不太明白 “验证” ,能具体些么  。 还有 Invalid stops这个错误 也是需要验证?

 
//+------------------------------------------------------------------+
//| 检查订单交易量的正确性                                               |
//+------------------------------------------------------------------+
bool CheckVolumeValue(double volume,string &description)
  {
//--- 交易操作允许的最小交易量
   double min_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
   if(volume<min_volume)
     {
      description=StringFormat("交易量小于允许的最小交易量,SYMBOL_VOLUME_MIN=%.2f",min_volume);
      return(false);
     }

//--- 交易操作允许的最大交易量 
   double max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
   if(volume>max_volume)
     {
      description=StringFormat("交易量大于允许的最大交易量,SYMBOL_VOLUME_MAX=%.2f",max_volume);
      return(false);
     }

//--- 取得交易量变化的最小步长
   double volume_step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);

   int ratio=(int)MathRound(volume/volume_step);
   if(MathAbs(ratio*volume_step-volume)>0.0000001)
     {
      description=StringFormat("交易量不是最小交易步长的整数倍,SYMBOL_VOLUME_STEP=%.2f, 最接近的正确交易量是 %.2f",
                               volume_step,ratio*volume_step);
      return(false);
     }
   description="正确的交易量数值";
   return(true);
  }


除此之外,还需要验证当前账号资金是否够开仓等等,具体阅读这篇文章:

https://www.mql5.com/zh/articles/2555

交易机器人在市场发布前必须经过的检验
交易机器人在市场发布前必须经过的检验
  • www.mql5.com
如果市场的管理人员在检验您产品的过程中发现了任何错误,您都将必须把它们全部修改好。本文家恶少了开发者们在他们的技术指标和交易机器人中最常犯下的错误,我们还推荐您阅读以下文章: 怎样快速捕捉和修复交易机器人中的错误 资金不足以进行交易操作 如果检查显示,资金不足以进行交易操作,就有必要在记录中输出一个错误消息而不是调用 OrderSend() 函数。检验实例: 交易操作中的无效交易量 这个函数很简单: 取得允许的最大订单数并赋予max_allowed_orders变量; 如果它不等于0,把它与当前订单数量做比较。但是,这个函数没有考虑到另外的可能的限制 - 对某一特定交易品种开启仓位总交易量的限制和挂单数量的限制。 某特定交易品种的手数限制...
 
//----check SL of buy/sell order meet SYMBOL_TRADE_STOPS_LEVEL    slptValue is target SL or PT
     double AskPrice = GetAsk(symbol);
   double BidPrice = GetBid(symbol);
   int stops_level=(int)SymbolInfoInteger(symbol,SYMBOL_TRADE_STOPS_LEVEL)+2;
   int freeze_level=(int)SymbolInfoInteger(symbol,SYMBOL_TRADE_FREEZE_LEVEL)+2;

   double point=SymbolInfoDouble(symbol,SYMBOL_POINT);

//----check SL of buy/sell order meet SYMBOL_TRADE_STOPS_LEVEL 
      if(orderType == ORDER_TYPE_BUY )
           {
            double minSLofBuy=BidPrice-stops_level*point;
            slptValue = MathMin(slptValue, minSLofBuy);
           }
      if(orderType == ORDER_TYPE_SELL )  
           {
            double minSLofSell=AskPrice+stops_level*point;
            slptValue = MathMax(slptValue, minSLofSell);          
           }
           
      if(orderType == ORDER_TYPE_BUY_STOP || orderType == ORDER_TYPE_BUY_LIMIT)    
           {
            double minSLofBuy=price-stops_level*point;
            slptValue = MathMin(slptValue, minSLofBuy);           
           } 
      if(orderType == ORDER_TYPE_SELL_STOP || orderType == ORDER_TYPE_SELL_LIMIT)    
           {
            double minSLofSell=price+stops_level*point;
            slptValue = MathMax(slptValue, minSLofSell);            

           }  

//----check PT of buy/sell meet SYMBOL_TRADE_STOPS_LEVEL 

      if(orderType == ORDER_TYPE_BUY)

           {

            double minPTofBuy=BidPrice+stops_level*point;

            slptValue = MathMax(slptValue, minPTofBuy);

           }

      if(orderType == ORDER_TYPE_SELL)

           {

            double minPTofSell=AskPrice-stops_level*point;

            slptValue = MathMin(slptValue, minPTofSell);          

           }

      if(orderType == ORDER_TYPE_BUY_STOP || orderType == ORDER_TYPE_BUY_LIMIT)           

           {

            double minPTofBuy=price+stops_level*point;

            slptValue = MathMax(slptValue, minPTofBuy);

           }

      if(orderType == ORDER_TYPE_SELL_STOP || orderType == ORDER_TYPE_SELL_LIMIT)

           {

            double minPTofSell=price-stops_level*point;

            slptValue = MathMin(slptValue, minPTofSell);          

           }
 
Ziheng Zhuang:


除此之外,还需要验证当前账号资金是否够开仓等等,具体阅读这篇文章:

https://www.mql5.com/zh/articles/2555



你好 不知道我哪理解不对。 我对SYMBOL_TRADE_STOPS_LEVEL 验证的代码修改如上一条评论,还是会Invalid stops。 注意到都是在 Modification failed之后,我对SYMBOL_TRADE_FREEZE_LEVEL的验证又做了 如下一条评论。

 


//在更改挂单 止盈 止损的函数中,增加了SYMBOL_TRADE_FREEZE_LEVEL的现在

//----Block setting PT or SL  of buy/sell pending order to meet SYMBOL_TRADE_FREEZE_LEVEL

//----slptValue=0 means no change to SL or PT
      if(orderType == ORDER_TYPE_BUY_LIMIT)
           {
            bool check;
            check=((AskPrice-price)>freeze_level*point);
            if(!check) slptValue=0;
           } 
      if(orderType == ORDER_TYPE_SELL_LIMIT)
           {
            bool check;
            check=((price-BidPrice)>freeze_level*point);
            if(!check) slptValue=0;
           }                   
      if(orderType == ORDER_TYPE_BUY_STOP)
           {
            bool check;
            check=((price-AskPrice)>freeze_level*point);
            if(!check) slptValue=0;
           }   
      if(orderType == ORDER_TYPE_SELL_STOP)
           {
            bool check;
            check=((BidPrice-price)>freeze_level*point);
            if(!check) slptValue=0;
           }                       
     }

//删除挂单的函数中,增加了不满足SYMBOL_TRADE_FREEZE_LEVEL要求不删除订单的代码

bool OrderDelete(ulong ticket)

  {

   ZeroMemory(mrequest);

   ZeroMemory(mresult);


   mrequest.action = TRADE_ACTION_REMOVE;

   //mrequest.magic = magicNumber;

   mrequest.order = ticket;

   

//----block  OrderDelete to meet SYMBOL_TRADE_FREEZE_LEVEL

   string orderSymbol = OrderGetString(ORDER_SYMBOL);

   ENUM_ORDER_TYPE orderType = (ENUM_ORDER_TYPE) OrderGetInteger(ORDER_TYPE);

   

   int freeze_level=(int)SymbolInfoInteger(orderSymbol,SYMBOL_TRADE_FREEZE_LEVEL)+2;

   double price=OrderGetDouble(ORDER_PRICE_OPEN);

   double AskPrice = GetAsk(orderSymbol);

   double BidPrice = GetBid(orderSymbol);

   double point=SymbolInfoDouble(orderSymbol,SYMBOL_POINT);

         

      if(orderType == ORDER_TYPE_BUY_LIMIT)

           {

            bool check;

            check=((AskPrice-price)>freeze_level*point);

            if(!check) return false;

           } 

      if(orderType == ORDER_TYPE_SELL_LIMIT)

           {

            bool check;

            check=((price-BidPrice)>freeze_level*point);

            if(!check) return false;

           }                   

      if(orderType == ORDER_TYPE_BUY_STOP)

           {

            bool check;

            check=((price-AskPrice)>freeze_level*point);

            if(!check) return false;

           }   

      if(orderType == ORDER_TYPE_SELL_STOP)

           {

            bool check;

            check=((BidPrice-price)>freeze_level*point);

            if(!check) return false;

           }                       

  

//--- action and return the result

   return(OrderSend(mrequest, mresult));

  }


//+------------------------------------------------------------------+

//开挂单的时候,调整挂单价格

//Adjust  pending price  in open pengding order function  to meet SYMBOL_TRADE_FREEZE_LEVEL      curPrice is pending price 


   int freeze_level=(int)SymbolInfoInteger(correctedSymbol,SYMBOL_TRADE_FREEZE_LEVEL)+2;

   double point=SymbolInfoDouble(correctedSymbol,SYMBOL_POINT);

   double ask=GetAsk(correctedSymbol);

   double bid=GetBid(correctedSymbol);   

   

   if(type==ORDER_TYPE_BUY_LIMIT) curPrice=MathMin(ask-freeze_level*point,curPrice);

   if(type==ORDER_TYPE_BUY_STOP) curPrice=MathMax(ask+freeze_level*point,curPrice);

   if(type==ORDER_TYPE_SELL_LIMIT) curPrice=MathMax(bid+freeze_level*point,curPrice);

   if(type==ORDER_TYPE_SELL_STOP) curPrice=MathMin(bid-freeze_level*point,curPrice);


//在仓位修改、关闭的函数中 加上以下block,满足SYMBOL_TRADE_FREEZE_LEVEL对仓位的要求

//block modify buy position to meet SYMBOL_TRADE_FREEZE_LEVEL

      bool check;

      check=((PositionGetDouble(POSITION_TP)-bid>freeze_level*point)&&(bid-PositionGetDouble(POSITION_SL)>freeze_level*point));

      if(!check) return false;//block modify buy position

//block modify sell position to meet SYMBOL_TRADE_FREEZE_LEVEL

      bool check;

      check=((ask-PositionGetDouble(POSITION_TP)>freeze_level*point)&&(PositionGetDouble(POSITION_SL)-ask>freeze_level*point));

      if(!check) return false;//block modify sell position 

 
V.xbb5146 Q.280726108:
可以试试把单量规范一下!

您好!单量更改没问题了 stop_level 和freeze_level的更改你觉得还差什么? 谢谢