如何编写均线多空变色指标?

 

以下代码在MT4中显示不了,请朋友们提点:

//+------------------------------------------------------------------+
#property copyright   "2005-2015, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Moving Average"
#property strict

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Green

int InpMAPeriod=56;        // Period
//--- indicator buffer
double AscendLine[];
double DescendLine[];
double FullLine[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   int    draw_begin=InpMAPeriod-1;
   IndicatorDigits(Digits);
//--- check for input
   if(InpMAPeriod<2)
      return(INIT_FAILED);
//--- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexDrawBegin(0,draw_begin);
   SetIndexDrawBegin(1,draw_begin);
//--- indicator buffers mapping
   SetIndexBuffer(0,AscendLine);
   SetIndexBuffer(1,DescendLine);
//--- initialization done
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|  Moving Average                                                  |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//--- check for bars count
   if(rates_total<InpMAPeriod-1 || InpMAPeriod<2)
      return(0);
//--- first calculation or number of bars was changed
   if(prev_calculated==0)
   {
      ArrayInitialize(AscendLine,0);
      ArrayInitialize(DescendLine,0);
      ArrayInitialize(FullLine,0);
   }
//--- calculation
   CalculateEMA(rates_total,prev_calculated,close);
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|  exponential moving average                                      |
//+------------------------------------------------------------------+
void CalculateEMA(int rates_total,int prev_calculated,const double &price[])
  {
   int    i,limit;   
   double SmoothFactor=2.0/(1.0+InpMAPeriod);
   //--- first calculation or number of bars was changed
   if(prev_calculated==0)
     {
      limit=InpMAPeriod;
       FullLine[0]=price[0];
      for(i=1; i<limit; i++)
         FullLine[i]=price[i]*SmoothFactor+FullLine[i-1]*(1.0-SmoothFactor);        
     }
   else
      limit=prev_calculated-1;
   //--- main loop
   for(i=limit; i<rates_total && !IsStopped(); i++)
   {
      FullLine[i]=price[i]*SmoothFactor+FullLine[i-1]*(1.0-SmoothFactor);  
      AscendLine[i]=EMPTY_VALUE;
      DescendLine[i]=EMPTY_VALUE;
      if(FullLine[i-1]<=FullLine[i]) 
      {     
         AscendLine[i]=FullLine[i];
      }
      else
      {
         DescendLine[i]=FullLine[i];  
      }
    }      
   //---
  }