Problem On Adding MA to Osma Indicator

 

Hello Every one

im trying to add Moving Average to OsMa Indicator:

What's wrong with that?

#property  copyright "Copyright © 2004, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Silver
#property  indicator_width1  2
//colour for signal line
#property  indicator_color2  Red
#property  indicator_width2  1
//---- indicator parameters
extern int FastEMA=8;
extern int SlowEMA=12;
extern int SignalSMA=9;
//external variable for the period of the signal line
extern int MAPer = 1;
//---- indicator buffers
double     OsmaBuffer[];
double     MacdBuffer[];
double     SignalBuffer[];
//we need an additional buffer for the signal line
double     MASignalBuffer[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(4);
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,OsmaBuffer);
   SetIndexDrawBegin(0,SignalSMA);
   SetIndexLabel(0,"Osma"); 
   SetIndexBuffer(1,MacdBuffer);
   SetIndexLabel(1,"Macd"); 
   SetIndexBuffer(2,SignalBuffer);
   SetIndexLabel(2,"Macd Signal"); 
   
   SetIndexStyle(3,DRAW_LINE);
   
   SetIndexDrawBegin(3,MAPer);
   SetIndexBuffer(3,MASignalBuffer);
   SetIndexLabel(3,"MA Signal"); 

   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Average of Oscillator                                     |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- macd counted in the 1-st additional buffer
   for(int i=0; i<limit; i++)
      MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd additional buffer
   for(i=0; i<limit; i++)
      SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
//---- main loop
   for(i=0; i<limit; i++)
      OsmaBuffer[i]=MacdBuffer[i]-SignalBuffer[i];




for( i=0; i<limit; i++)
     MASignalBuffer[i]=iMAOnArray(OsmaBuffer,Bars,MAPer,0,MODE_SMA,i);


     
   return(0);
  }
//+------------------------------------------------------------------+