Combine Osma and MA for a custom indicator

 
I've been trying to turn the osma indicator into an ma indicator by turning the histogram into an ma line, and then also adding the option of making the osma-ma line sma, ema, smma,or lwma but my coding knowledge/experience is not enough. I've relized that it would have to be a separate window and I've been able to do besides that is get the osma to plot as a line, I've also gotten the code to when calculating the ma to look at the product of the osma code instead of Close[], and I replaced all the MA_period from the MA indicator with SignalSMA from the Osma indicator...but thats as far as I can get and it's plotting nothing. Can some one please help me? thanks a million.


#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue
#property  indicator_width1  2
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
extern int MA_Shift=0;
extern int MA_Method=0;
//---- indicator buffers
double ExtMapBuffer[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   int    draw_begin;
   string short_name;
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexShift(0,MA_Shift);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   if(SignalSMA<2) SignalSMA=13;
   draw_begin=SignalSMA-1;
//---- indicator short name
   switch(MA_Method)
     {
      case 1 : short_name="EMA(";  draw_begin=0; break;
      case 2 : short_name="SMMA("; break;
      case 3 : short_name="LWMA("; break;
      default :
         MA_Method=0;
         short_name="SMA(";
     }
   IndicatorShortName(short_name+SignalSMA+")");
   SetIndexDrawBegin(0,draw_begin);
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
  if(Bars<=SignalSMA) return(0);
   ExtCountedBars=IndicatorCounted();
//---- check for possible errors
   if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
   if (ExtCountedBars>0) ExtCountedBars--;
//----
   switch(MA_Method)
     {
      case 0 : sma();  break;
      case 1 : ema();  break;
      case 2 : smma(); break;
      case 3 : lwma();
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+
//| Simple Moving Average                                            |
//+------------------------------------------------------------------+
void sma()
  {
   int limit;
   double Macd[],Signal[],Osma[];
   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++)
      Macd[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++)
      Signal[i]=iMAOnArray(Macd,Bars,SignalSMA,0,MODE_SMA,i);
//---- main loop
   for(i=0; i<limit; i++)
      Osma[i]=Macd[i]-Signal[i];
      
   double sum=0;
   int pos=Bars-ExtCountedBars-1;
//---- initial accumulation
   if(pos<SignalSMA) pos=SignalSMA;
   for(i=1;i<SignalSMA;i++,pos--)
      sum+=Osma[pos];
//---- main calculation loop
   while(pos>=0)
     {
      sum+=Osma[pos];
      ExtMapBuffer[pos]=sum/SignalSMA;
	   sum-=Osma[pos+SignalSMA-1];
 	   pos--;
     }
//---- zero initial bars
   if(ExtCountedBars<1)
      for(i=1;i<SignalSMA;i++) ExtMapBuffer[Bars-i]=0;
  }
//+------------------------------------------------------------------+
//| Exponential Moving Average                                       |
//+------------------------------------------------------------------+
void ema()
  {
   int limit;
   double Macd[],Signal[],Osma[];
   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++)
      Macd[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++)
      Signal[i]=iMAOnArray(Macd,Bars,SignalSMA,0,MODE_SMA,i);
//---- main loop
   for(i=0; i<limit; i++)
      Osma[i]=Macd[i]-Signal[i];
      
   double pr=2.0/(SignalSMA+1);
   int    pos=Bars-2;
   if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
//---- main calculation loop
   while(pos>=0)
     {
      if(pos==Bars-2) ExtMapBuffer[pos+1]=Osma[pos+1];
      ExtMapBuffer[pos]=Osma[pos]*pr+ExtMapBuffer[pos+1]*(1-pr);
 	   pos--;
     }
  }
//+------------------------------------------------------------------+
//| Smoothed Moving Average                                          |
//+------------------------------------------------------------------+
void smma()
  {
   int limit;
   double Macd[],Signal[],Osma[];
   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++)
      Macd[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++)
      Signal[i]=iMAOnArray(Macd,Bars,SignalSMA,0,MODE_SMA,i);
//---- main loop
   for(i=0; i<limit; i++)
      Osma[i]=Macd[i]-Signal[i];
      
   double sum=0;
   int k,pos=Bars-ExtCountedBars+1;
//---- main calculation loop
   pos=Bars-SignalSMA;
   if(pos>Bars-ExtCountedBars) pos=Bars-ExtCountedBars;
   while(pos>=0)
     {
      if(pos==Bars-SignalSMA)
        {
         //---- initial accumulation
         for(i=0,k=pos;i<SignalSMA;i++,k++)
           {
            sum+=Osma[k];
            //---- zero initial bars
            ExtMapBuffer[k]=0;
           }
        }
      else sum=ExtMapBuffer[pos+1]*(SignalSMA-1)+Osma[pos];
      ExtMapBuffer[pos]=sum/SignalSMA;
 	   pos--;
     }
  }
//+------------------------------------------------------------------+
//| Linear Weighted Moving Average                                   |
//+------------------------------------------------------------------+
void lwma()
  {
   int limit;
   double Macd[],Signal[],Osma[];
   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++)
      Macd[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++)
      Signal[i]=iMAOnArray(Macd,Bars,SignalSMA,0,MODE_SMA,i);
//---- main loop
   for(i=0; i<limit; i++)
      Osma[i]=Macd[i]-Signal[i];
      
   double sum=0.0,lsum=0.0;
   double price;
   int weight=0,pos=Bars-ExtCountedBars-1;
//---- initial accumulation
   if(pos<SignalSMA) pos=SignalSMA;
   for(i=1;i<=SignalSMA;i++,pos--)
     {
      price=Osma[pos];
      sum+=price*i;
      lsum+=price;
      weight+=i;
     }
//---- main calculation loop
   pos++;
   i=pos+SignalSMA;
   while(pos>=0)
     {
      ExtMapBuffer[pos]=sum/weight;
      if(pos==0) break;
      pos--;
      i--;
      price=Osma[pos];
      sum=sum-lsum+price*SignalSMA;
      lsum-=Osma[i];
      lsum+=price;
     }
//---- zero initial bars
   if(ExtCountedBars<1)
      for(i=1;i<SignalSMA;i++) ExtMapBuffer[Bars-i]=0;
  }
//+------------------------------------------------------------------+


Reason: