[存档]任何菜鸟问题,为了不使论坛变得杂乱无章。专业人士,不要路过。没有你就无处可去 - 3. - 页 202

 
Vinin:

或者,也许只是在EA的帮助下制定一个活跃工具的清单。这个方法有点复杂。可以用更简单的方法来解决这个问题
我们可以简单地在输入参数中指定一个数字,但问题是,在交易过程中,可能会出现某些货币暂停交易的情况。那么其他货币的EA应该重新计算他们的参数。
 
forexnew:
你可以简单地在输入参数中指定一个数字,但问题是,在交易过程中,可能会出现某些货币暂停交易的情况。那么其他货币的EA就必须重新计算其参数。

为什么要说明。专家顾问可以自己得到它。同时,它还可以管理其他专家顾问。一切都取决于任务
 

Figar0:

В самой функции ошибок нет, наверно ошибки возникают при попытке ее использовать, но это вы нам не показываете. Выкладывайте то что не компилится прямо файлом и гадать будет не надо.

//+------------------------------------------------------------------+
//|                                                  MACD Sample.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+

extern double TakeProfit = 50;
extern double TrailingStop = 30;
extern double MACDOpenLevel=3;
extern double MACDCloseLevel=2;
extern double MATrendPeriod=26;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   double MacdCurrent, MacdPrevious, SignalCurrent;
   double SignalPrevious, MaCurrent, MaPrevious;
   int cnt, ticket, total;
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external 
// variables (Lots, StopLoss, TakeProfit, 
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
   if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  
     }
   if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return(0);  // check TakeProfit
     }
double Lots()      // Расчет используемого лота
  {
   double Lots;
   Lots=AccountFreeMargin()/10000*5;
   Lots=MathMin(15,MathMax(0.1,Lots));
   if(Lots<0.1) 
     Lots=NormalizeDouble(Lots,2);
   else
     {
     if(Lots<1) Lots=NormalizeDouble(Lots,1);
     else       Lots=NormalizeDouble(Lots,0);
     }
     return(Lots);
  }
//+------------------------------------------------------------------+  

// to simplify the coding and speed up access
// data are put into internal variables
   MacdCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0);
   MacdPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
   SignalCurrent=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0);
   SignalPrevious=iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1);
   MaCurrent=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,0);
   MaPrevious=iMA(NULL,0,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,1);

   total=OrdersTotal();
   if(total<1) 
     {
      // no opened orders identified
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);  
        }
      // check for long position (BUY) possibility
      if(MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious &&
         MathAbs(MacdCurrent)>(MACDOpenLevel*Point) && MaCurrent>MaPrevious)
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"macd sample",16384,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("Error opening BUY order : ",GetLastError()); 
         return(0); 
        }
      // check for short position (SELL) possibility
      if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious && 
         MacdCurrent>(MACDOpenLevel*Point) && MaCurrent<MaPrevious)
        {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"macd sample",16384,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
           }
         else Print("Error opening SELL order : ",GetLastError()); 
         return(0); 
        }
      return(0);
     }
   // it is important to enter the market correctly, 
   // but it is more important to exit it correctly...   
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
            // should it be closed?
            if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
               MacdCurrent>(MACDCloseLevel*Point))
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
                 return(0); // exit
                }
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else // go to short position
           {
            // should it be closed?
            if(MacdCurrent<0 && MacdCurrent>SignalCurrent &&
               MacdPrevious<SignalPrevious && MathAbs(MacdCurrent)>(MACDCloseLevel*Point))
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
               return(0); // exit
              }
            // check for trailing stop
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
  }
// the end.
 
Vinin:

你为什么要指定这个?专家顾问可以自己获得。同时,它还可以管理其他专家顾问。这一切都取决于任务。

我不知道管理其他EA的情况。该EA在所有货币对上都是一样的,模式是这样的。

如果有两个货币对:第一个货币对显示2,第二个货币对显示1。

如果3个货币对:第一个显示3,第二个显示2,第三个显示1

如果是4个货币对:第一个显示4,第二个显示3,第三个显示2,第四个显示1。

我有一种感觉,第一种货币的计算结果没有被其他货币对的专家顾问考虑在内,或者它在某种程度上取决于打开的窗口(货币对)的数量!我想这是一个问题。

 
Vinin:

为什么要说明。议员可以自己去拿。同时,他还可以管理其他顾问。这一切都取决于任务。
谢谢你。我自己已经想明白了。我只需要删除这一行,并从1开始计算KP。
if(OrderSymbol()==Symbol())   break;
 
skyjet:

对于初学者来说,你的手数计算函数是在start函数里面声明的。把它拿出来。然后会出现一些未声明变量的错误,但我认为你可以自己处理。
 
skyjet:
为什么在手数计算中需要NormalizeDlouble()?

为了使逗号后有两个数字。否则,0.009手的头寸将不会被打开,因为它不是最小手数的倍数。

   double Lots;
   Lots=AccountFreeMargin()/10000*5;
   Lots=MathMin(15,MathMax(0.1,Lots));
   if(Lots<0.1) 
     Lots=NormalizeDouble(Lots,2);
   else
     {
     if(Lots<1) Lots=NormalizeDouble(Lots,1);// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     else       Lots=NormalizeDouble(Lots,0);// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     } 

 

伙计们!

我如何使每40个订单成为大批量?:: 市场和待定

这个怎么样?

int Nom = OrderTicket();                        // Номер ордера

a= Nom%40;                                      // к-во делить на 40 без остатка
if a = 0
lot = 2;  

 
 
Figar0:

对于初学者来说,你的手数计算函数是在start函数里面声明的。把它拿出来。然后会出现一些未声明变量的错误,但我认为你可以自己处理。
谢谢你的帮助。
 
DDFedor:
空中喷气机
在手数计算中,NormalizeDlouble()的作用是什么?

为了使逗号后有两个数字。否则,一个手数为0.009的头寸将不会被打开,因为它不是最小手数的倍数步骤。

谢谢你的澄清。