有什么帮助吗? - 页 2

 
WHRoeder:
  1. 当然不是。准确地说,是 "RTFM"。你只有在从开始返回时才能得到一个新的勾。
  2. RTFM和测试器的限制,你不能在测试器中睡觉。
  3. 什么是函数的返回值?我如何使用它们?- MQL4论坛


谢谢你的帮助,我已经删除了while循环,并在每次执行订单时中断到start函数,删除了IsTesting函数(目前),我的OrderSend似乎正在工作。


现在运行它,无论我在哪里有一个Print()函数,都没有出现在日志(或日志簿)中,最初的订单打开时很好,然后就没有了 - 即使我把我的打印订单作为代码中的下一行?

 
j.w.msb:

谢谢您的帮助,我已经删除了 while 循环和每次执行订单时的 start 函数,删除了 IsTesting 函数(目前),我的 OrderSend 似乎正在工作。


现在运行它,无论我在哪里有Print()函数,都没有出现在日志中(或日志簿),最初的订单打开得很好,然后就没有了--即使我把打印订单作为代码中的下一行?


你的代码现在看起来如何?
 
很抱歉,这是个噩梦!我试着在策略测试器中寻找错误信息,但谷歌没有帮助。我试着在策略测试器中 寻找错误的信息,但谷歌并没有提供帮助:s
//+------------------------------------------------------------------+
//|                                                   SMA scripy.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
extern int z=1234;
int total;
//---
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   int i;
   total=0;
   if (OrdersTotal()!=0)
      {
      for (i=OrdersTotal()-1; i>=0; i--)                                                     
         {
         if (OrderSelect(i,SELECT_BY_POS))
            {
            if ((OrderSymbol()==Symbol())&&(OrderMagicNumber()==z))
               {
               if ((OrderType()==OP_BUY)&&(iMA(Symbol(),0,6,0,MODE_SMA,PRICE_CLOSE,0)<iMA(Symbol(),0,21,0,MODE_SMA,PRICE_CLOSE,0)))
                  { 
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);                  
               }
               if ((OrderType()==OP_SELL)&&(iMA(Symbol(),0,6,0,MODE_SMA,PRICE_CLOSE,0)>iMA(Symbol(),0,21,0,MODE_SMA,PRICE_CLOSE,0)))
                  {
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);                  
               }
               else 
                  {
                  total++;                                                                 
               }
            }
         }
      }
   }
//----
   return;
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
}
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int start()
   {
//----
   int i,L;
   if (AccountBalance()>50)                                                                                     
   {
//-----
double SMA6=iMA(Symbol(),0,6,0,MODE_SMA,PRICE_CLOSE,0);
double SMA21=iMA(Symbol(),0,21,0,MODE_SMA,PRICE_CLOSE,0);
double RSI70=iRSI(Symbol(),PERIOD_D1,14,PRICE_CLOSE,0)<70;
double RSI30=iRSI(Symbol(),PERIOD_D1,14,PRICE_CLOSE,0)>30;                                                                                                            
//----
   if (total==0)
      {
      if ((RSI70)&&(SMA6>SMA21))
         {                                                                                                                       
         OrderSend(Symbol(),OP_BUY,0.1,Ask,0,0,0,"",z,0,Red); 
         Print("WE ARE HERE");
         total+=1;                                                       
      }
      if ((RSI30)&&(SMA6<SMA21))
         {
         OrderSend(Symbol(),OP_SELL,0.1,Bid,0,0,0,"",z,0,Blue);
         total+=1;
      }  
   }
//---
   if (total!=0)
      {
      L=0;
      for (i=OrdersTotal()-1; i>=0; i--)                                                    
         {
         if (OrderSelect(i,SELECT_BY_POS))
            {
            if ((OrderSymbol()==Symbol())&&(OrderMagicNumber()==z))
               {
               if ((OrderType()==OP_BUY)&&(SMA6<SMA21))
                  { 
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);
                     total+=-1;
                     break;
               }
               if ((OrderType()==OP_SELL)&&(SMA6>SMA21))
                  {
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);                 
                     total+=-1;
                     break;
               }
               else 
                  {
                  L++;                                                                  
               }
            }
            total=L;
         }
      }
   }
//----
}
//----
return;
}
//-------------------------------------------
 

double, int, string, bool, datetime, color, ........ 我必须使用什么???....

//-----
double SMA6=iMA(Symbol(),0,6,0,MODE_SMA,PRICE_CLOSE,0);
Print("SMA6=  ",SMA6);
double SMA21=iMA(Symbol(),0,21,0,MODE_SMA,PRICE_CLOSE,0);
Print("SMA21=  ",SMA21);
double RSI70=iRSI(Symbol(),PERIOD_D1,14,PRICE_CLOSE,0)<70;
Print("RSI70=  ",RSI70);
double RSI30=iRSI(Symbol(),PERIOD_D1,14,PRICE_CLOSE,0)>30;
Print("RSI30=  ",RSI30);                                                                                                            
//----

它们是双倍的吗?

         OrderSend(Symbol(),OP_BUY,0.1,Ask,0,0,0,"",z,0,Red); 
         Print("WE ARE HERE");

SEEEEEE什么是函数的返回值 ?我如何使用它们?- MQL4论坛

大的解释

当一个函数返回一个int,如OrderSend(),我们可以使用这样的代码来检查该函数是否工作,如果没有工作,就向日志报告错误。

int TicketNumber;

TicketNumber = OrderSend( . . . . . . . . );

**(*******************)
   {
   Print(******************);
   }
else
   {
   Print(************************);
   }

. 请看WHRoeder提供的链接,你会发现我在这里用星星隐藏的东西 ......

也可以用它来检查关闭交易

在你的代码....,这样,当订单发送失败时,你就知道是什么类型的错误,以及错误来自哪里。

.

如果订单关闭失败会发生什么.......?????

 

RSI和MA都是双数,所以变量也需要是双数,不是吗?

https://docs.mql4.com/indicators/iRSI && https://docs.mql4.com/indicators/iMA

我编入了打印错误的代码,但是没有任何东西被打印到日志中,所以我无法确定哪些错误发生了?我是不是还漏掉了什么明显的东西?现在我又回到了打开卖出,然后无法关闭的状态......

//+------------------------------------------------------------------+
//|                                                   SMA scripy.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
extern int z=1234;
int total;
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   int i;
   total=0;
   if (OrdersTotal()!=0)
      {
      for (i=OrdersTotal()-1; i>=0; i--)                                                     
         {
         if (OrderSelect(i,SELECT_BY_POS))
            {
            if ((OrderSymbol()==Symbol())&&(OrderMagicNumber()==z))
               {
               if ((OrderType()==OP_BUY)&&(iMA(Symbol(),0,6,-3,MODE_SMA,PRICE_CLOSE,0)<iMA(Symbol(),0,21,0,MODE_SMA,PRICE_CLOSE,0)))
                  { 
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);                  
               }
               if ((OrderType()==OP_SELL)&&(iMA(Symbol(),0,6,-3,MODE_SMA,PRICE_CLOSE,0)>iMA(Symbol(),0,21,0,MODE_SMA,PRICE_CLOSE,0)))
                  {
                  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);                  
               }
               else 
                  {
                  total++;                                                                 
               }
            }
         }
      }
   }
//----
   return;
}
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int start()
   {
//----
   int ticket,i,L;
   bool x;
   if (AccountBalance()>50)                                                                                     
   {
//-----
double SMA6=iMA(Symbol(),0,6,-3,MODE_SMA,PRICE_CLOSE,0);
Print("SMA6 is ",SMA6);
double SMA21=iMA(Symbol(),0,21,0,MODE_SMA,PRICE_CLOSE,0);
Print("SMA21 is ",SMA21);
double RSI70=iRSI(Symbol(),PERIOD_D1,14,PRICE_CLOSE,0)<70;
Print("RSI70 is ",RSI70);
double RSI30=iRSI(Symbol(),PERIOD_D1,14,PRICE_CLOSE,0)>30; 
Print("RSI30 is ",RSI30);                                                                                                           
//----
   if (total==0)
      {
      if ((RSI70)&&(SMA6>SMA21))
         {                                                                                                                       
         ticket=OrderSend(Symbol(),OP_BUY,v(AccountBalance()),Ask,0,0,0,"",z,0,Red); 
         total+=1;                                                       
         if (ticket<0)
            {
            Print("OrderSend Failed", GetLastError());
         }
      }
      if ((RSI30)&&(SMA6<SMA21))
         {
         ticket=OrderSend(Symbol(),OP_SELL,v(AccountBalance()),Bid,0,0,0,"",z,0,Blue);
         total+=1;
         if (ticket<0)
            {
            Print("OrderSend Failed", GetLastError());
         }
      }  
   }
//---
   if (total!=0)
      {
      L=0;
      for (i=OrdersTotal()-1; i>=0; i--)                                                    
         {
         if (OrderSelect(i,SELECT_BY_POS))
            {
            if ((OrderSymbol()==Symbol())&&(OrderMagicNumber()==z))
               {
               if ((OrderType()==OP_BUY)&&(SMA6<SMA21))
                  { 
                  x=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);
                     if (x==false)
                        {
                        Print("Error is ", GetLastError());
                     }
                     else total+=-1;
                     break;
               }
               if ((OrderType()==OP_SELL)&&(SMA6>SMA21))
                  {
                  x=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Green);   
                     if (x==false)
                        {
                        Print("Error is ", GetLastError());
                     }
                     else 
                        {
                        total+=-1;
                     }
                     break;
               }
               else 
                  {
                  L++;                                                                  
               }
            }
            total=L;
         }
      }
   }
//----
}
//----
return;
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
}
//-------------------------------------------------------------------+
double v(double k)
{
   double v=((k*0.015)/1000);
   if (v<MarketInfo(Symbol(),MODE_MINLOT))
      {
      v=MarketInfo(Symbol(),MODE_MINLOT);
      return(v);
   }
   else
      {
      return(v);
   }
}
//-------------------------------------------------------------------+
 

duuuhhhh iRSI是双倍的,但比较结果是1 - 所以我用RSI替换了RSI30和RSI70,并进行了比较,所有的工作都很顺利。但当我把SMA6改为移位时,它总是输出SMA6=0,为什么?

谢谢大家的帮助!我希望下一次不要再这么烦人了!

 
j.w.msb:

RSI和MA都是双数,所以变量也需要是双数,不是吗?

https://docs.mql4.com/indicators/iRSI && https://docs.mql4.com/indicators/iMA

我编入了打印错误的代码,但没有任何东西被打印到日志中,所以我无法确定哪些错误发生了?我是不是还漏掉了什么明显的东西?现在我又回到了开盘卖出,然后无法关闭的状态......

将该EA放在模拟账户 的图表上

不要只看终端杂志...
也要看终端专家.....

你在那里看到了什么打印

 
deVries:

在模拟账户的图表上放置该EA

不要只看终端日志 ...
也要看终端专家.....

你在那里看到了什么?


现在正在打印和执行:)感谢您的帮助--我错误地将iRSI<70定义为双数(因为它是一个比较),导致了问题。它现在打印出来了,并按预期工作,除了,如果我改变了SMA移位,它打印的SMA=0?
 
j.w.msb:

现在正在打印和执行:)感谢您的帮助--我错误地将iRSI<70定义为双数(因为它是一个比较),导致了问题。它现在打印出来了,并按预期工作,除了,如果我改变了SMA移位,它打印的SMA=0?

在您的EA图表上放置一个具有相同设置的SMA,看看您做了什么 ...
 
   if (total==0)
      {
      if ((RSI70)&&(SMA6>SMA21))
         {                                                                                                                       
         ticket=OrderSend(Symbol(),OP_BUY,v(AccountBalance()),Ask,0,0,0,"",z,0,Red); 
         total+=1;                                                       
         if (ticket<0)
            {
            Print("OrderSend Failed", GetLastError());
         }
      }

为什么你的总数+=1。

在这一刻,我不知道订单结束是否成功

如果它失败了,我不知道它试图打开什么订单类型,也可能是你试图打开的卖出交易。