下载MetaTrader 5
要添加评论,请登录注册
您需要程序员吗?自由工作服务将会找到您需要的开发者
Fa Cao
1143
Fa Cao 2013.12.03 07:19 

做了一个指标 Indicator_1,然后在EA中调用,打印指标数组中的数据,结果有些乱,详情如下:

Indicator_1代码:

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow 
double Bar_High[]; 

int init()
  {
  IndicatorShortName("High_Low_Two_Lines");
  IndicatorBuffers(1);
  SetIndexBuffer(0,Bar_High);
  SetIndexStyle(0,DRAW_LINE);
  SetIndexLabel(0,"High Point Line");
  SetIndexDrawBegin(0,0);
  return(0);
  }

int deinit()
  {
   return(0);
  }

int start()
  {
    int counted_bars=IndicatorCounted();
    if(counted_bars>0)int limit=Bars-counted_bars-1;
    limit=Bars-counted_bars;
    for(int i=0;i<limit;i++)
    {
    Bar_High[0]=High[iHighest(NULL,0,MODE_HIGH,10,0)];
    Print("Bar_High[0-9]:",Bar_High[0]," , ",Bar_High[1]," , ",Bar_High[2]," , ",Bar_High[3]," , ",Bar_High[4]," , ",Bar_High[5]," , ",Bar_High[6]," , ",Bar_High[7]," , ",Bar_High[8]," , ",Bar_High[9]);
    }
   return(0);
  }


  
 

EA代码为:


int init()
  {
   return(0);
  }
int deinit()
  {
   return(0);
  }

int start()
{
   iCustom(NULL,0,"High_Low_Ind",30,40,50,0,0);
  return(0);
}

用历史数据测试结果为:这个结果有问题,指标缓存Bar_High[0]每获取一个值,则原来的值应该赋给Bar_High[1], Bar_High[1]原来值给Bar_High[2],以此类推,但是结果并非如此,请问是哪里出问题了?

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:59 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:58 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:58 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.347, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294


...........

2013.12.03 15:11:49 2013.11.28 23:54 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.325, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:54 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.325, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:54 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.325, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:54 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.325, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:54 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.325, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:54 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.325, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:54 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.325, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:54 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.325, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:54 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.325, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:54 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.325, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:54 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.325, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:54 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.325, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:53 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.325, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:53 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.322, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:53 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.32, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:53 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.318, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:53 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.318, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:53 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.318, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294

2013.12.03 15:11:49 2013.11.28 23:53 High_Low_Ind USDJPY,M15: Bar_High[0-9]:102.318, 102.287, 102.286, 102.268, 102.257, 102.257, 102.294, 102.294, 102.294, 102.294


okwh
1629
okwh 2013.12.03 13:37  

Bar_High[0]=High[iHighest(NULL,0,MODE_HIGH,10,0)];

你只给下标0的元素赋值,还能得到那么多?因为mt不是那样类推的, 如果是那样推,用i有什么意义?

应该改为:

Bar_High[i]=High[iHighest(NULL,0,MODE_HIGH,10,i)];

Fa Cao
1143
Fa Cao 2013.12.03 23:54  
DxdCn:

Bar_High[0]=High[iHighest(NULL,0,MODE_HIGH,10,0)];

你只给下标0的元素赋值,还能得到那么多?因为mt不是那样类推的, 如果是那样推,用i有什么意义?

应该改为:

Bar_High[i]=High[iHighest(NULL,0,MODE_HIGH,10,i)];


谢谢回复,有道理,还有一个问题想请教一下:

比如此例,指标缓存数组为Bar_High[],如果代码如下写:

Bar_Shift=iHighest(NULL,0,MODE_HIGH,10,i);

Bar_High[i+Bar_Shift]=High[Bar_Shift];

即是想实现这样的功能:从当前Bar开始,往前推10根Bar,选出其中最高的一根,然后将选出的所有的”最高的“Bar作为指标连接成线;请问这样用指标实现是否合适?

okwh
1629
okwh 2013.12.04 04:39  

可以,当然你知道这是事后画点和线,有延迟,是类似ZigZag和fractal的指标。

Bar_Shift是i到i+10之间的值,不是0~10之间的值,不需要加i,所以

Bar_High[Bar_Shift]=High[Bar_Shift]; 即可

参考 弄清i 是什么,如何随时间变化

https://book.mql4.com/samples/icustom

Fa Cao
1143
Fa Cao 2013.12.04 06:56  
谢谢!
BaiChun Li
838
BaiChun Li 2013.12.06 04:43  
DxdCn:

可以,当然你知道这是事后画点和线,有延迟,是类似ZigZag和fractal的指标。

Bar_Shift是i到i+10之间的值,不是0~10之间的值,不需要加i,所以

Bar_High[Bar_Shift]=High[Bar_Shift]; 即可

参考 弄清i 是什么,如何随时间变化

https://book.mql4.com/samples/icustom

还是DxdCn厉害,我看半天没看明白怎么回事,后来去看了一眼代码,发现还是代码比较少Bar_High[0]=High[iHighest(NULL,0,MODE_HIGH,10,0)]

/
要添加评论,请登录注册