一个初学者的求助,谢谢

 

敬爱的ROSH版主好,各位达人好

我是个MQL4语言初学者,自己在尝试编写指标,但遇到问题,最终无法输出数据导致指标无法画出线条。

只好向大家求助。

//+------------------------------------------------------------------+
//|                                                     andre*a6.mq4 |
//|                       Copyright ?2004, MetaQuotes Software Corp. |
//|                                       https://www.metaquotes.net// |
//+------------------------------------------------------------------+
#property  copyright "Copyright ?2004, MetaQuotes Software Corp."
#property  link      "https://www.metaquotes.net//"
//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 1
#property  indicator_color1  White
//---- indicator parameters
extern int AtrPeriod=21;
//----
double  C3[];
//---- indicator buffers
double  ind_buffer1[];
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   SetIndexDrawBegin(0,AtrPeriod);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- 6 indicator buffers mapping   
   SetIndexBuffer(0,ind_buffer1);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("andre");
   SetIndexLabel(0,"ind_buffer1");
//---- initialization done
   return(0);
  }
 
//+------------------------------------------------------------------+
//| andre                                                            |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int i,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;
 
//---- counted in the TEMP buffer
   for(i=0; i<limit; i++)
      {
      C3[i]=iMA(NULL,0,21,0,MODE_SMA,PRICE_CLOSE,i);
      }
//---- D1 counted in the 1-st buffer 
   for(i=0; i<limit; i++)
      ind_buffer1[i]=iMAOnArray(C3,0,AtrPeriod,0,MODE_SMA,i);
//----
   return(0);
      }  
//+------------------------------------------------------------------+

ind_buffer1为恒量可以显示,但一旦使用ima或者imaonarray就无法输出数据,更无法在屏幕上显示指标线。

恳请大家帮帮忙,指出我的语句错误,或者帮忙编辑一下,输出正确。

 

修改添加:

int init()
{
IndicatorBuffers(2);

............

SetIndexBuffer(2,C3);
.............................

OK!

 

谢谢Dxdcn副班班~

十分感谢,虽然还不能很明白,但解决了问题。

再次感谢。

 
But only so be more correct:
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   SetIndexDrawBegin(0,AtrPeriod);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- 6 indicator buffers mapping   
   SetIndexBuffer(0,ind_buffer1);
   SetIndexBuffer(1,C3);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("andre");
   SetIndexLabel(0,"ind_buffer1");
//---- initialization done
   return(0);
  }
 

副班班???

MT没请我做班,我只是好心帮你,跟MT无关的了。

道理很简单,SetIndexBuffer(2,C3);这样C3才是真的数组(分配空间放东西),前面的double  C3[];只是起个数组名字。

没有这一句,赋值不起作用。

 

您一解说我明白了

弄错您身份了,呵呵

不好意思

在此也感谢ROSH先生对我的帮助。

 
DxdCn:

副班班???

MT没请我做班,我只是好心帮你,跟MT无关的了。

道理很简单,SetIndexBuffer(2,C3);这样C3才是真的数组(分配空间放东西),前面的double C3[];只是起个数组名字。

没有这一句,赋值不起作用。

Sorry. Thank you.
原因: