shadowczy 2007-12-19 14:41
请求帮助!谢谢(MT4编程)
请求帮助!谢谢(MT4编程)
我是新手,在学习MT4编程,下面的程序在MT4中为什么没有显示啊?
请高手指点,谢谢!!
//+------------------------------------------------------------------+
//| CZY.mq4 |
//| Copyright ?2007, MetaQuotes Software Corp. |
//| [url]http://www.metaquotes.net[/url] |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 White
extern int Xperiod=14;
extern int Maperiod1=5;
double ind_buffer0[];
double ind_buffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexBuffer(0,ind_buffer0);
IndicatorShortName("CZY("+Maperiod1+")");
SetIndexLabel(0,"CZY");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit,i;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//----
for(i=0; i<limit; i++)
ind_buffer1=iRSI(NULL,0,Xperiod,PRICE_CLOSE,i);
for(i=0; i<limit; i++)
ind_buffer0=iMAOnArray(ind_buffer1,0,Maperiod1,0,MODE_EMA,i);
//----
return(0);
}
//+------------------------------------------------------------------+
[[i] 本帖最后由 shadowczy 于 2007-12-19 15:32 编辑 [/i]]
xfxyldj 2007-12-19 18:13
你的代码问题很多。[code]for(i=0; i<limit; i++)
ind_buffer1=iRSI(NULL,0,Xperiod,PRICE_CLOSE,i);
for(i=0; i<limit; i++)
ind_buffer0=iMAOnArray(ind_buffer1,0,Maperiod1,0,MODE_EMA,i);
这两句应为
for(i=0; i<limit; i++)
ind_buffer1[i]=iRSI(NULL,0,Xperiod,PRICE_CLOSE,i);
for(i=0; i<limit; i++)
ind_buffer0[i]=iMAOnArray(ind_buffer1,0,Maperiod1,0,MODE_EMA,i);[/code]还有程序中你用到了两个数组缓存。但是前面的定义中只有一个。
因此在init()函数中需要增加对ind_buffer1[]的缓存定义。
增加。[code]IndicatorBuffers(2);//放在最前面。
SetIndexBuffer(1,ind_buffer1); [/code]其他代码没看。你先调试看看吧
shadowczy 2007-12-19 20:12
谢谢您,我以自己搞定!
没有[ i ]可能是copy时显示问题!呵呵!
[[i] 本帖最后由 shadowczy 于 2007-12-19 20:15 编辑 [/i]]
xfxyldj 2007-12-19 21:34
回复 4楼 的帖子
搞定了,贴个解决办法嘛!以供他人借鉴!
谢谢!