烦请各路高手拨冗指教

 

小弟学着做了一个移动平均线的指标。原理很简单。两条各自带有不同shfit参数的简单移动平均线和一条由它俩相加再除以2的曲线。编译没发现有错,但在MT4上显示不正常。我左右看不出问题出在哪里。只好烦请各路高手帮着给看一下下了。谢谢先啦。

代码如下:

//---------------------------------------
#property  indicator_chart_window
#property  indicator_buffers 3            
#property  indicator_color1 Red 
#property  indicator_color2 Yellow  
#property  indicator_color3 LimeGreen   
  
extern int  M1=20;
extern int  M2=60;
extern int  Shift1=10;
extern int  Shift2=30;
double ma1[];
double ma2[];
double ma[];
int init()
  {
    IndicatorBuffers(3);
    SetIndexBuffer(0,ma1);
    SetIndexStyle(0,DRAW_LINE);
    SetIndexBuffer(1,ma2);
    SetIndexStyle(0,DRAW_LINE);
    SetIndexBuffer(2,ma);
    SetIndexStyle(0,DRAW_LINE);

   return(0);
  }
int start()
  {
   int limit;   
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   for(int i=0; i<limit; i++)
   
   ma1=iMA(NULL,0,M1,Shift1,MODE_SMA,PRICE_CLOSE,i);
   ma2=iMA(NULL,0,M2,Shift2,MODE_SMA,PRICE_CLOSE,i);
   ma=(ma1 + ma2)/2;

   return(0);
}
//+------------------------------------------------------------------+
 
   for(int i=0; i<limit; i++)
   {
     ma1[i] = iMA(NULL,0,M1,Shift1,MODE_SMA,PRICE_CLOSE,i);
     ma2[i] = iMA(NULL,0,M2,Shift2,MODE_SMA,PRICE_CLOSE,i);
     ma[i] = (ma1[i] + ma2[i])/2;
   }
 
谢谢 GreatShore
原因: