新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 - 页 726

 
Igor Petrov:

非常感谢!

请告诉我在测试EA 时是否可以使用(CHARTEVENT_CLICK)?
 
Yuriy Vins:
请告诉我这个(CHARTEVENT_CLICK)是否可以在测试EA 时使用?

唉,没有。

 
ukrop1203:

我在 "历史中心 "菜单中下载了MetaQuotes软件公司的数据,经纪人的数据与此有什么关系?

谁下载的终端,这就是数据被拉入MT4的地方。更准确地说,也是最有可能的是--你在下载的时候登录了谁的账户,它就从那里提取历史记录。

 
Vladimir Baskakov:
你在说什么?

像你这样的人应该被剥夺你的销售员身份。去做一个环卫工人学徒吧。

 
Andrei Novichkov:

像你这样的人应该被剥夺销售员的身份。去做一个环卫工人学徒吧。

祝您有一个愉快的一天。
 

大家好。

我在EA中放了一个关闭订单的按钮,但它关闭了终端中的所有订单。我只是需要它在当前的图表上。能否请您帮忙?

//----------------------------------------------------------------------
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---            
   if(sparam== "CloseButton")
      {
      CloseAllOpenPositions(MaxSlippage); 
      ObjectSetInteger(0,"CloseButton",OBJPROP_STATE,false);    
      }   
      if(sparam== "CloseBuy")
      {
      CloseAllBuy(MaxSlippage); 
      ObjectSetInteger(0,"CloseBuy",OBJPROP_STATE,false);    
      }         
         if(sparam== "CloseSell")
      {
      CloseAllSell(MaxSlippage); 
      ObjectSetInteger(0,"CloseSell",OBJPROP_STATE,false);    
      }         
//---      
  }
  
//+------------------------------------------------------------------+
void CloseAllOpenPositions(int intMaxSlippage)
  {
   bool checkOrderClose = true;        
   int index = OrdersTotal()-1;   
   while (index >=0 && OrderSelect (index,SELECT_BY_POS,MODE_TRADES)==true)
      {
         
      if (OrderType()==OP_BUY || OrderType()==OP_SELL)
         {         
         checkOrderClose = OrderClose (OrderTicket(), OrderLots(), OrderClosePrice(), MaxSlippage, CLR_NONE); 
         
         if(checkOrderClose == false)
            {
            int errorCode = GetLastError();
            
            if (errorCode == 1 || errorCode == 2 || errorCode == 5 || errorCode == 6 || errorCode == 64 || errorCode == 65 || errorCode == 132 || errorCode == 133 || errorCode == 139) break;
            else continue;        
            }          
         }           
      index--;
     }     
  }
  //----------------------------------------------------------------------------
 
Carcass77:

大家好。

我在EA中放了一个关闭订单的按钮,但它关闭了终端中的所有订单。我只是需要它在当前的图表上。能否请您帮忙?

替换关闭功能

//+------------------------------------------------------------------+
void CloseAllOpenPositions(int intMaxSlippage)
  {
   bool checkOrderClose=true;
   int index=OrdersTotal()-1;
   while(index>=0 && OrderSelect(index,SELECT_BY_POS,MODE_TRADES)==true)
     {
      if(OrderSymbol()==Symbol())   //Добавил  
        {

         if(OrderType()==OP_BUY || OrderType()==OP_SELL)
           {
            checkOrderClose=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),intMaxSlippage,CLR_NONE);

            if(checkOrderClose==false)
              {
               int errorCode=GetLastError();

               if(errorCode==1 || errorCode==2 || errorCode==5 || errorCode==6 || errorCode==64 || errorCode==65 || errorCode==132 || 
                errorCode==133||errorCode==139) break;
               else continue;
              }
           }

        }
      index--;
     }
  }
//+------------------------------------------------------------------+
 
Alekseu Fedotov:

替换关闭功能

它正在发挥作用。非常感谢你。

 
另外,想在每笔交易中添加一个步数的乘数功能。有什么提示吗?
 
Carcass77:
另外,想在每笔交易中增加一个步数的乘数功能。有什么提示吗?

如果是相对于已经开出的订单的最大手数增加新订单的手数,那么在计算订单时,请记住订单的最大手数。

像这样。

//_______________________________________________________________________
//возвращает суммарное кол-во открытых рыночных ордеров, в переменных
// lotmaxbuy_ и lotmaxsell_ вернет максимальные лоты по типам ордеров
int NumberOfOrders(int magic_,double &lotmaxbuy_,double &lotmaxsell_)
  {
   int i,ot,buy_=0,sell_=0,k=OrdersTotal();
   lotmaxbuy_=0.0; lotmaxsell_=0.0;
   for(i=0; i<k; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         ot=OrderType();
         if((OrderMagicNumber()==magic_) && (OrderSymbol()==_Symbol))
           {
            if(ot==OP_BUY) { buy_++;  lotmaxbuy_  = fmax(lotmaxbuy_,OrderLots());  }
            if(ot==OP_SELL){ sell_++; lotmaxsell_ = fmax(lotmaxsell_,OrderLots()); }
           }
        }
     }
   return(buy_+sell_);
  }
//+------------------------------------------------------------------+