穿越0轴的画线问题

 

小弟是个新手,试编了一个指标,希望实现当指标线在0轴之上指标线颜色显示为绿色,在0轴之下显示为红色,但是运行后发现,在穿越0轴时的指标线为空白。其他部分显示正常,见附图,请大家指点,非常感谢!!!代码如下:
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_level1 0.00
extern int FMA=12;
extern int SMA=26;
double buf1[];
double buf2[];
double buftemp;
int init()
{
SetIndexBuffer(0,buf1);
SetIndexBuffer(1,buf2);
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);

return(0);
}
int start()
{
int limit=Bars-IndicatorCounted();
for(int i=0; i<limit; i++)
{
buftemp=iMA(NULL,0,FMA,0,1,0,i)-iMA(NULL,0,SMA,0,1,0,i);
if (buftemp<0) buf1=buftemp;
if (buftemp>0) buf2=buftemp;
}
return(0);
}

 
最简单的方法就是把DRAW_LINE换成DRAW_HISTOGRAM
 
你试试这个
//+------------------------------------------------------------------+
//|                                                         zero.mq4 |
//|                                             Copyright 2010, trad |
//|                                            du_steven@hotmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, trad"
#property link      "du_steven@hotmail.com"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_level1 0.00

extern int FMA=12;
extern int SMA=26;
double buf1[];
double buf2[];
double buftemp,buftemp1;
int init()
{
   SetIndexBuffer(0,buf1);
   SetIndexBuffer(1,buf2);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);

   return(0);
}
int start()
{
   int limit=Bars-IndicatorCounted();
   for(int i=0; i<limit; i++)
   {
      buftemp=iMA(NULL,0,FMA,0,1,0,i)-iMA(NULL,0,SMA,0,1,0,i);
      buftemp1=iMA(NULL,0,FMA,0,1,0,i+1)-iMA(NULL,0,SMA,0,1,0,i+1);
      
      if (buftemp<0)
      { 
         buf1[i]=buftemp; 
         if(buftemp1>0)
            buf1[i+1] = buftemp1;
      }
      
      if(buftemp>0)
      {
         buf2[i]=buftemp;
         if(buftemp1<0)
            buf2[i+1] = buftemp1;
      }
      
   }
   return(0);
}
 

感谢指点,尤其感谢trad兄,出现这个原因是连接处的数据中断,不过稍有遗憾的是trad兄的代码虽然上下连接平滑了,但是在0轴转折点处颜色显示不对,看来在MT4中此问题是无法解决了,不知在mt5中能否实现?最后再一次感谢二位兄弟指点。

 
哈哈,颜色过界了是不是? 这个没办法呀,因为不能在一个点上画两种颜色,别盼MT5了,没戏。
原因: