//+------------------------------------------------------------------+
//|                                                     Mom_OsMA.mq4 |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

extern int Momentum=10;
extern int MA_Period=8;
extern int MA_Method=MODE_EMA;
extern int MA_Shift=0;

extern int CountBar=1000;

//---- buffers
double ExtMapBuffer0[];
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
int init()
  {
   IndicatorBuffers(4);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(2,ExtMapBuffer0);
   SetIndexBuffer(3,ExtMapBuffer3);
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
  {
   int l=0;
   if (CountBar>Bars) {l=Bars;}else{l=CountBar;}
   for (int i=l;i>=0;i--){
      ExtMapBuffer3[i]=iCustom(Symbol(),0,"###Momentum###",Momentum,0,i);
   }
   for (i=l;i>=0;i--){
      ExtMapBuffer1[i]=0;
      ExtMapBuffer2[i]=0;
      ExtMapBuffer0[i]=0;
      double g=iMAOnArray(ExtMapBuffer3,0,MA_Period,MA_Shift,MA_Method,i);
      ExtMapBuffer0[i]=ExtMapBuffer3[i]-g;
      if (ExtMapBuffer0[i]>0) ExtMapBuffer1[i]=ExtMapBuffer0[i];
      if (ExtMapBuffer0[i]<0) ExtMapBuffer2[i]=ExtMapBuffer0[i];
   }
   return(0);
  }

