帮助。为什么EA不关闭交易 - 页 7

 

你不觉得20000 次重试有点过分吗。如果它连续5次关闭失败,那么就该退出了。

如果关闭失败,能打印出错误信息就更好了。

 
我不再喂养巨魔了......。
 

你好,crossy。

你说得对,我只看到了你的部分代码,你可能有不同的计划,而且阅读4000行的代码肯定无助于头脑清醒--我也是。

你说你的EA不能关闭交易。所以我们必须找出造成这种情况的原因并加以处理。我是这样认为的。

:D

#include <stdlib.mqh>   
   ...
for(int pos = OrdersTotal(); pos >= 0 ; pos--) 
   {
   if ( OrderSelect(pos, SELECT_BY_POS, MODE_TRADES) 
        && OrderMagicNumber() == My_Magic_Number
        && OrderSymbol() == Symbol())
      {
       if (OrderType() = OP_BUY) // we close long
         {
         for (int try_to_close = 1; try_to_close <= 100; try_to_close ++)
            {
            bool success = OrderClose (OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, Yellow);
            if (success = false)
               {
               int Error = GetLastError();
               Print ("Unable to close ticket ",OrderTicket()," with error ",ErrorDescription(Error)); // from #include <stdlib.mqh>
               if (TRY_CLOSE_AGAIN_OR_NOT(Error) == false ) break; // 
               }
            }
         }
         
       if (OrderType() = OP_SELL) // we close short
         {
         // do the same with sell
         
         }
      }   
   }
//+------------------------------------------------------------------+
bool TRY_CLOSE_AGAIN_OR_NOT(int err) // True
  {
  switch (err)
     {
      case 1:   return (false); //error_string="no error";                                                 
      case 2:   return (false); //error_string="common error";                                          
      case 3:   return (false); //error_string="invalid trade parameters";                                
      case 4:   Sleep (500); return (true); //error_string="trade server is busy";                               
      case 5:   return (false); //error_string="old version of the client terminal";                  
      case 6:   Sleep (500); return (true); //error_string="no connection with trade server";                 
      case 7:   return (false); //error_string="not enough rights";                                
      case 8:   Sleep (500); return (true); //error_string="too frequent requests";                                
      case 9:   return (false); //error_string="malfunctional trade operation (never returned error)"; 
      case 64:  return (false); //error_string="account disabled";                        
      case 65:  return (false); //error_string="invalid account";                   
      case 128: Sleep (500); return (true); //error_string="trade timeout";                                    
      case 129: return (false); //error_string="invalid price";                               
      case 130: return (false); //error_string="invalid stops";                          
      case 131: return (false); //error_string="invalid trade volume";                 
      case 132: return (false); //error_string="market is closed";                      
      case 133: return (false); //error_string="trade is disabled";                       
      case 134: return (false); //error_string="not enough money";                   
      case 135: return (false); //error_string="price changed";                         
      case 136: return (false); //error_string="off quotes";                              
      case 137: Sleep (500); return (true); //error_string="broker is busy (never returned error)";    
      case 138: return (false); ////error_string="requote";                                 
      case 139: return (false); //error_string="order is locked";                           
      case 140: return (false); //error_string="long positions only allowed";                 
      case 141: return (false); //error_string="too many requests";                               
      //case 145: return (true); //error_string="modification denied because order too close to market";  
      case 146: Sleep (500); return (true); //error_string="trade context is busy";                              
      //case 147: return (true); error_string="expirations are denied by broker";                    
      //case 148: return (true); error_string="amount of open and pending orders has reached the limit"; 
      //case 149: return (true); error_string="hedging is prohibited";                                   
      case 150: return (false); //error_string="prohibited by FIFO rules";  
      default : return (false);         
     }
     
  return(false); // can not manage the err we get out
  }
 

所以,你有一个问题,即不是所有的订单都被关闭。您粘贴的这段代码 - 永远不会关闭所有的订单。因此,如果您需要帮助,请粘贴所有与订单关闭有关的代码。没有必要粘贴所有的代码(我知道你想保密),但如果不粘贴部分代码,你永远不会得到帮助,这涉及到的问题(在这种情况下 - 没有空头订单关闭的代码)。

 
onewithzachy:

你好,crossy。

你说得对,我只看到了你的部分代码,你可能有不同的计划,而且阅读4000行的代码肯定无助于头脑清醒--我也是。

你说你的EA不能关闭交易。所以我们必须找出造成这种情况的原因并加以处理。我是这样认为的。

:D


谢谢onewithzachy的这个主意。它在任何地方都很有用,因为它在这里。

请让它再工作几个小时,我保证会向你汇报。

也感谢Raptor,感谢他的良好贡献。

Y.

 

你好。

正如我所承诺的那样,在6个小时后,EA工作了,一切正常,这要感谢你的

好的想法。

所以,与此同时,让我们继续前进,我希望不会有任何问题。

Y.

 
crossy:

你好。

正如我所承诺的那样,在6个小时后,EA工作了,一切正常,这要感谢你的

好的想法。

所以,与此同时,让我们继续前进,我希望不会有任何问题。

Y.

很好!,请在一周内再次向我们更新。

:D