在后面的测试中发现问题,找不到根本原因! - 页 5

 
jollydragon:

.我还是看不出山峰的消失。如何 "重新初始化 "它?

你可以通过改变时间框架来重新初始化

打开指标输入窗口并点击确定

 

GumRai2015.05.14 21:51#

You can re-initialise by either changing timeframes

or

打开指标输入窗口,点击确定


经过尝试,我理解为和我说的山峰位置变化是同一个意思。正确吗?

亲爱的GumRai。

 
WHRoeder:

对于每一次迭代,(除了第一次,)Fish1 是前一个缓冲区元素的值,但你并没有将它初始化为ExtBuffer1[limit]

所以对于初始迭代(当limit == bars),你设置ExtBuffer1[0] = 1.1*ExtBuffer1[1]

但是,对于随后的ticks(当limit == 1时)你设置ExtBuffer1[0] = 1.1*0.00001

亲爱的WHRoeder。

非常感谢您,在您的指导下,我对这个问题有了些许了解。

但是,可能还需要一些问题来进一步澄清。

1.你可以看到 "double Fish1=0.00001; "被定义在所有函数的开始和结束部分。

所以它应该是全局变量,而且我知道它已经被分配到了最后的ExBuffer1[0],即使随后有新的刻度出现。

还是每次有新的刻度出现时,它都会自动恢复到 "0.00001"?

2.现在每个条形图都以不同的方式画出一个或多个后续条形图,为什么我可以在实时M1图表中看到重新画出...,bar[8],...,或bar[1],而没有任何中断?

3.为什么刷新后峰值的位置会改变?

4.为什么在实时M1图表中,我可以看到一些峰值(约959870576)比"EMPTY_VALUE"(2147483647)少很多很多?

5.如果有一个新的柱子出现,以前的ExtBuffer1[0]会自动变为ExtBuffer1[1]。正确吗?

6.如何防止任何可能的重新初始化或重新画图?

也许我在一些关键点上还很困惑,需要你的极大耐心来帮助我!如果您能逐一帮助解决这些问题,我们将不胜感激!

 

亲爱的WHRoeder,GumRai,

在再次阅读您的帖子后,我根据我的理解将我的指标更新为下面的代码。

在使用它进行反向测试后,结果与指标更加一致。但是,仍然有2个问题。请参考下面的屏幕截图。

1.交易发生在从第一笔订单开始的4个指标信号之后。

2.2.仍然有一个订单变化发生在指标信号之前的4个小节。

以下是更新的指标代码。

#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.50"
#property strict
#property  indicator_separate_window
#property  indicator_buffers 2

extern int    period=35;
extern double smooth=0.3;

datetime       lastAlertTime;
double         ExtBuffer0[];
double         ExtBuffer1[];
double         ExtValue[];
double         Value1=0,Buffer0_1=0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorBuffers(3);
   SetIndexBuffer(0,ExtBuffer0); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,clrWhiteSmoke);
   SetIndexBuffer(1,ExtBuffer1); SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,clrGoldenrod);
   SetIndexBuffer(2,ExtValue);
   IndicatorShortName(" Solar Joy   ^v^  ");
   ArraySetAsSeries(ExtBuffer0,true);
   ArraySetAsSeries(ExtBuffer1,true);
   ArraySetAsSeries(ExtValue,true);

   SetIndexDrawBegin(1,period);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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[])
  {
   if(rates_total<=period)    return(0);

   int    i,limit;
   double price,MinL,MaxH;

   if(prev_calculated<rates_total-1) limit=rates_total-period-1;
   else                              limit=1;

   for(i=limit-1; i>=0; i--)
     {
      MaxH = High[iHighest(NULL,0,MODE_HIGH,period,i)];
      MinL = Low[iLowest(NULL,0,MODE_LOW,period,i)];
      price=(High[i]+Low[i])/2;
      if(limit==1)
        {
         Value1=ExtValue[1];
         Buffer0_1=ExtBuffer0[1];
        }
      ExtValue[i]=(1-smooth)*(2*(price-MinL)/(MaxH-MinL)-1.0) + smooth*Value1;
      ExtValue[i]=MathMin(MathMax(ExtValue[i],-0.999),0.999); // Value=Value>0.999?0.999:Value<-0.999?-0.999:Value;
      ExtBuffer0[i]=(1-smooth)*MathLog((1+ExtValue[i])/(1-ExtValue[i]))+smooth*Buffer0_1;
      Value1=ExtValue[i];
      Buffer0_1=ExtBuffer0[i];
      if(ExtBuffer0[i]>0) ExtBuffer1[i]=3;
      else ExtBuffer1[i]=-3;
     }

   return(rates_total);
  }
//+------------------------------------------------------------------+

 
jollydragon:

1.你可以看到 "double Fish1=0.00001; "被定义在所有函数的开始和结束部分。

所以它应该是全局变量,而且我知道它已经被分配到了最后的ExBuffer1[0],即使后来有了新的刻度。

还是每次有新的刻度出现时,它都会自动恢复到 "0.00001"?

不是,也不是。但你没有把它初始化为ExtBuffer1[limit]"中的哪一部分不清楚?
if(prev_calculated<rates_total-1){ limit=rates_total-period-1; Fish1=0.00001;       }
else                             { limit=1;                    Fish1=ExtBuffer0[1]; }
for(i=limit-1; i>=0; i--)
  {
   ExtBuffer1[i]=1.1*Fish1;
   Fish1=ExtBuffer1[i];
   if(Fish1>=EMPTY_VALUE)
      Fish1=1;
  }

就个人而言,我认为rate_total/prev_calculated/OnCalculate参数是一个可恶的东西,因为图表/缓冲区是时间序列,所以会用老方法来做。
int counted = IndicatorCounted();
limit = Bars - MathMax(counted, period-1); // Lookback period-1
Fish1 = counted == 0 ? 0.00001 : ExtBuffer0[limit];
for(i=limit-1; i>=0; i--)