我的指标在我换到新的时间框架图时就消失了

 

你好。

我开始使用一个指标(第一部分)。当改变时间框架时,它运行良好。

然后我添加了第二部分,即。如果Close[i]-Close[i+1]小于过去100条差值的中位数,我将为所有缓冲区赋值0。

现在这个组合指标在一个图表中运行良好,但当我改变时间框架时,这个指标就消失了。我必须把它重新连接到图表上。

我认为这个问题是由Array引起的,但我不知道如何解决它。

谁能帮我解决这个错误?

非常感谢你。

SCFX

//+------------------------------------------------------------------+
//|                                                          hf1.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              httakeprofit://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "httakeprofit://www.mql5.com"
#property version   "1.00"
#property strict

//--- indicator settings
//#property indicator_chart_window
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_width1 2  
#property indicator_width2 2 
#property indicator_width3 1 
#property indicator_width4 1 
#property indicator_width5 1 

#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Orange
#property indicator_color5 Orange

//--- input parameter
input int kperiod=30;
input int dperiod=9;
input int slow=9;
input int sample_roc_quartile=100;

//--- buffers
double buy[];
double sell[];
double stoploss[];
double takeprofit1[];
double takeprofit2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void) //*/*/*/*/*/
  {
//--- indicator buffers mapping
//--- 1 additional buffer used for counting.
   //IndicatorBuffers(6);
   IndicatorDigits(Digits);
//--- indicator line
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexBuffer(0,buy);
   SetIndexArrow(0,241);
   
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexBuffer(1,sell);
   SetIndexArrow(1,242);

   SetIndexStyle(2,DRAW_ARROW);
   SetIndexBuffer(2,stoploss);

   SetIndexStyle(3,DRAW_ARROW);
   SetIndexBuffer(3,takeprofit2); 
         
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexBuffer(4,takeprofit1);  
   
  
//--- name for DataWindow and indicator subwindow label

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
      int limit=rates_total-prev_calculated;
      
      double roc_s[];
      ArrayResize(roc_s,sample_roc_quartile+1);

//---

//------------------------------------------ 

for(int i=0; i<limit; i++)
{  

//FIRST PSART 

   if(iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i)>iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i)   &&   iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i+1)<iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i+1))   
      {  buy[i]=Close[i]; 
         stoploss[i]=Low[i]-0.005; 
         takeprofit1[i]=Close[i]+0.005;
         takeprofit2[i]=Close[i]+0.01;
         }
      
   if(iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i)<iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i)   &&   iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i+1)>iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i+1))   
      {  sell[i]=Close[i]; 
         stoploss[i]=High[i]; 
         takeprofit1[i]=Close[i]-0.0050;
         takeprofit2[i]=Close[i]-0.01;
         }   
         
//SECOND PART         
   for(int j=0;j<=sample_roc_quartile;j++)
   {
      roc_s[j]=Close[i+j]-Close[i+j+1];
      ArraySort(roc_s);
      
      if(   (Close[i]-Close[i+1])<roc_s[50]  )
         {  buy[i]=0; 
            stoploss[i]=0; 
            takeprofit1[i]=0;
            takeprofit2[i]=0;
         }
    }     
}
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

可能是数组超出范围 的错误,指标正在被删除

int limit=rates_total-prev_calculated;

for(int i=0; i<limit; i++)
iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i+1)<iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i+1))

你可能在日志中得到一个关于全局初始化失败的信息
检查你的日志

 

谢谢你的建议。

检查了 日志,没有错误或警告通知。

我不确定(i+1)是否会造成麻烦,因为单独存在(或简单地删除第二部分),这个指标可以正常工作。

庄家

 

有错误 我编译了你的代码并测试了它。

2014.05.22 22:39:43.936 自定义指标 Test Indicator 3 XAUUSD,M1: 已删除
2014.05.22 22:39:43.905 测试指标3 XAUUSD,M1:全局初始化失败
2014.05.22 22:39:43.905 测试指标3 XAUUSD,M5: uninit reason 3 //----------------------- change chart
2014.05.22 22:39:17.323 在'测试指标3.mq4'中阵列超出范围(117,32)
2014.05.22 22:39:15.591 测试指标3 XAUUSD,M5: 已初始化
2014.05.22 22:39:09.570 自定义指标Test Indicator 3 XAUUSD,M5:加载成功

 
scfx:

谢谢你的建议。

我检查了日志,没有错误或警告通知。

我不确定(i+1)是否会造成麻烦,因为单独存在(或简单地删除第二部分),这个指标可以正常工作。

SCFX


那么可能是这样的

roc_s[j]=Close[i+j]-Close[i+j+1];

你试图获取不存在的条形图的收盘价

 

你应该在指标首先启动时添加一行:prev_calculated == 0。

类似这样的内容。

 int limit = -100;
   if( prev_calculated == 0 ) limit = 3000;// will calculate 3000 Bars
    else                      limit = rates_total-prev_calculated;
      

在我的电脑上也没有错误;-)

 

嗨,ffoorr。

你的解决方案真的很好。

实话告诉你,我昨晚雇了个人来解决这个问题。是的,他做到了,但是代码的效率很低,请看下面,因为他多加了一个for(i)。

如果你能解释一下prev_calculated ==0是什么意思,我将不胜感激。

//+------------------------------------------------------------------+
//|                                                          hf1.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              httakeprofit://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "httakeprofit://www.mql5.com"
#property version   "1.00"
#property strict

//--- indicator settings
//#property indicator_chart_window
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_width1 2  
#property indicator_width2 2 
#property indicator_width3 1 
#property indicator_width4 1 
#property indicator_width5 1 

#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Orange
#property indicator_color5 Orange

//--- input parameter
input int kperiod=30;
input int dperiod=9;
input int slow=9;
input int sample_roc_quartile=100;

//--- buffers
double buy[];
double sell[];
double stoploss[];
double takeprofit1[];
double takeprofit2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void) //*/*/*/*/*/
  {
//--- indicator buffers mapping
//--- 1 additional buffer used for counting.
   //IndicatorBuffers(6);
   IndicatorDigits(Digits);
//--- indicator line
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexBuffer(0,buy);
   SetIndexArrow(0,241);
   
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexBuffer(1,sell);
   SetIndexArrow(1,242);

   SetIndexStyle(2,DRAW_ARROW);
   SetIndexBuffer(2,stoploss);

   SetIndexStyle(3,DRAW_ARROW);
   SetIndexBuffer(3,takeprofit2); 
         
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexBuffer(4,takeprofit1);  
   
  
//--- name for DataWindow and indicator subwindow label

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
      int limit=rates_total-prev_calculated;
          if(limit<=0)limit =2;
     
      double roc_s[];
      ArrayResize(roc_s,sample_roc_quartile+1);

//---

//------------------------------------------ 

for(int i=1; i<limit; i++)
{  

//FIRST PSART 

   if(iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i)>iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i)   
   &&   iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i+1)<iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i+1))   
      {  buy[i]=Close[i]; 
         stoploss[i]=Low[i]-0.005; 
         takeprofit1[i]=Close[i]+0.005;
         takeprofit2[i]=Close[i]+0.01;
         }
      
   if(iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i)<iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i)   
   &&   iStochastic(NULL,0,kperiod,dperiod,slow,0,0,0,i+1)>iStochastic(NULL,0,kperiod,dperiod,slow,0,0,1,i+1))   
      {  sell[i]=Close[i]; 
         stoploss[i]=High[i]; 
         takeprofit1[i]=Close[i]-0.0050;
         takeprofit2[i]=Close[i]-0.01;
         }   
} 

    
//SECOND PART   

//--------------------------------------- HERE IS THE WHAT HE DID
int mid = (sample_roc_quartile +1)/2;
  
for(int i=1; i<limit&&(i+1)<rates_total; i++)
{    

//---------------------------------------------


  for(int j=0;j<=sample_roc_quartile&&(i+j+1)<rates_total;j++)
   {
      roc_s[j]=Close[i+j]-Close[i+j+1];
      ArraySort(roc_s);
   }   
      
      if( (Close[i]-Close[i+1])<roc_s[mid]  )
         {  buy[i]=0; 
            stoploss[i]=0; 
            takeprofit1[i]=0;
            takeprofit2[i]=0;
         }
    
 }    

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

大家好...


我在安装IBFX MACD传统指标和其他模板到我的MT4时遇到了问题。

以前的版本,我只需要复制和粘贴我的文件到位于 "专家 "文件夹下的 "指标 "文件夹。

目前的版本只有 "MQL4 "文件夹,其中包括一个较小的 "专家 "和 "指标 "文件夹。

我已经试过在两个文件夹中都粘贴,并重新启动我的平台,但它就是不工作。

没有发生。

有谁能在这个问题上给我建议吗?或者有什么其他方法能让我得到带有2条EMA线的传统MACD指标

谢谢

道格拉斯
 
Douglas Beng 你需要停止把你的问题放在其他人的主题上,因为这与他们的主题无关。开始你自己的主题。
 
douglas_heng: 我在安装IBFX MACD传统指标和其他模板到我的MT4时遇到问题。
不要不要多个 (6) 帖子。不要劫持别人的帖子。
 
scfx:

嗨,ffoorr。

你的解决方案真的很好。

实话告诉你,我昨晚雇了个人来解决这个问题。是的,他做到了,但是代码的效率很低,请看下面,因为他多加了一个for(i)。

如果你能解释一下prev_calculated ==0是什么意思,我将不胜感激。


好吧,scfx,我不明白你的指标的第二部分,所以我不能说。

当一个指标第一次启动时,(放在图表上)previous_calculation在结构上等于零,所以可以固定指标开始计算的起始点。

if( prev_calculated == 0) limit = 100。

if( prev_calculated < 50) limit = 500。

或者说

if( prev_calculated < 500) limit = 3000: (都一样,不使用图表的开头)

int limit = -100;
   if( prev_calculated == 0 ) limit = 3000;// will calculate 3000 Bars
    else                      limit = rates_total-prev_calculated;

at the first lauch of the indicator limit = 3000;

for(int i=1; i<3000; i++) // draw 3000 bars 

at the second lauch limit = 0; // ( because rates_total-prev_calculated = 0)  ;
for(int i=1; i<0; i++)    //   draw the last bars only, faster

非常好的想法,这在......