如何解决错误代码129和136

 

求教 下面几行代码

if(z1>=Bid && Bid>=z2   )                    
         {        
         int ca=0;
         while(ca<5)
         {danhao=OrderSend(Symbol(),OP_BUY,lots,Ask,10,0,0,"my_buy",1001,0,Magenta);     
        
         if(danhao<=0){Print("开仓失败,danhao=",danhao );      Print(GetLastError()  );      Alert ( Symbol(),"开仓失败"  );   ca++;} 
         if(danhao>200){printf("开仓成功,danhao=%d",danhao,Symbol()  );  ca=5;  }                    
         }

      有时开仓成功,有时开仓失败并连续出现一个错误代码136和4个129。这是为什么??应该如何解决??

 

在MQL4\Libraries文件夹中有个stdlib.mq4,就是关于错误描述的文件。

用SymbolInfoDouble(Symbol(),SYMBOL_ASK) 代替Ask,你的问题就能解决。


//+------------------------------------------------------------------+
//|                                                       stdlib.mq4 |
//|                   Copyright 2005-2015, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "2005-2015, MetaQuotes Software Corp."
#property link      "http://www.mql4.com"
#property library
//+------------------------------------------------------------------+
//| return error description                                         |
//+------------------------------------------------------------------+
string ErrorDescription(int error_code)
  {
   string error_string;
//---
   switch(error_code)
     {
      //--- codes returned from trade server
      case 0:   error_string="no error";                                                   break;
      case 1:   error_string="no error, trade conditions not changed";                     break;
      case 2:   error_string="common error";                                               break;
      case 3:   error_string="invalid trade parameters";                                   break;
      case 4:   error_string="trade server is busy";                                       break;
      case 5:   error_string="old version of the client terminal";                         break;
      case 6:   error_string="no connection with trade server";                            break;
      case 7:   error_string="not enough rights";                                          break;
      case 8:   error_string="too frequent requests";                                      break;
      case 9:   error_string="malfunctional trade operation (never returned error)";       break;
      case 64:  error_string="account disabled";                                           break;
      case 65:  error_string="invalid account";                                            break;
      case 128: error_string="trade timeout";                                              break;
      case 129: error_string="invalid price";                                              break;
      case 130: error_string="invalid stops";                                              break;
      case 131: error_string="invalid trade volume";                                       break;
      case 132: error_string="market is closed";                                           break;
      case 133: error_string="trade is disabled";                                          break;
      case 134: error_string="not enough money";                                           break;
      case 135: error_string="price changed";                                              break;
      case 136: error_string="off quotes";                                                 break;
      case 137: error_string="broker is busy (never returned error)";                      break;
      case 138: error_string="requote";                                                    break;
      case 139: error_string="order is locked";                                            break;
      case 140: error_string="long positions only allowed";                                break;
      case 141: error_string="too many requests";                                          break;
      case 145: error_string="modification denied because order is too close to market";   break;
      case 146: error_string="trade context is busy";                                      break;
      case 147: error_string="expirations are denied by broker";                           break;
      case 148: error_string="amount of open and pending orders has reached the limit";    break;
      case 149: error_string="hedging is prohibited";                                      break;
      case 150: error_string="prohibited by FIFO rules";                                   break;
      //--- mql4 errors
      case 4000: error_string="no error (never generated code)";                           break;
      case 4001: error_string="wrong function pointer";                                    break;
      case 4002: error_string="array index is out of range";                               break;
      case 4003: error_string="no memory for function call stack";                         break;
      case 4004: error_string="recursive stack overflow";                                  break;
      case 4005: error_string="not enough stack for parameter";                            break;
      case 4006: error_string="no memory for parameter string";                            break;
      ......
      ......
      case 5028: error_string="string resize error";                                       break;
      case 5029: error_string="structure contains strings or dynamic arrays";              break;
      default:   error_string="unknown error";
     }
//---
   return(error_string);
  }

 
Ziheng Zhuang:

在MQL4\Libraries文件夹中有个stdlib.mq4,就是关于错误描述的文件。

用SymbolInfoDouble(Symbol(),SYMBOL_ASK) 代替Ask,你的问题就能解决。


还是不行
 
jocojohn:
还是不行

是啥原因不行?

写个脚本测试下就知道了

//+------------------------------------------------------------------+
//|                                                       test11.mq4 |
//|                                           Copyright 2020,fxMeter |
//|                            https://www.mql5.com/en/users/fxmeter |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020,fxMeter"
#property link      "https://www.mql5.com/en/users/fxmeter"
#property version   "1.00"
#property strict
#include <stdlib.mqh>
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
//---
   if(1)
   {
      int ca=0;
      double lots=0.1;
      while(ca<5)
      {
         int danhao=OrderSend(Symbol(),OP_BUY,lots,SymbolInfoDouble(Symbol(),SYMBOL_ASK),10,0,0,"my_buy",1001,0,Magenta);
         if(danhao<=0)
         {
            int error = GetLastError();
            printf("开仓失败,danhao= %d, 错误代码=%d, 错误原因=%s",danhao,error,ErrorDescription(error));
            Alert ( Symbol(),"开仓失败"  );
            ca++;
         }
         if(danhao>200)
         {
            printf("开仓成功,danhao=%d",danhao,Symbol() );
            ca=5;
            break;
         }
      }
   }
//---
}
//+------------------------------------------------------------------+
 
Ziheng Zhuang:

是啥原因不行?

写个脚本测试下就知道了

试了你的代码  偶尔会出现一次开仓失败  但是由于while 循环第二次又开仓成功了。所以总的来说问题解决了。非常感谢