//+------------------------------------------------------------------+
//|                                                mn MACD Histo.mq4 |
//+------------------------------------------------------------------+
#property copyright   "mn"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1  clrBlue
#property indicator_color2  clrRed
#property indicator_width1  2
#property indicator_width2  2
input int mMacdFast  = 12,
          mMacdSlow  = 26,
          mSignal    = 9;

double mMacdU[];
double mMacdD[];

//+------------------------------------------------------------------+
int OnInit(void)
  {
   IndicatorBuffers(2);
   IndicatorShortName(" ");
   IndicatorDigits(0);
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexStyle(1, DRAW_HISTOGRAM);
   SetIndexBuffer(0, mMacdU);
   SetIndexBuffer(1, mMacdD);

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
int start()
  {
   int counted_bars = IndicatorCounted(), mLimit;
  
   if (counted_bars == 0)
     counted_bars = mLimit +1;
   mLimit = (Bars - counted_bars);

   for(int i = mLimit; i >= 0; i--)
     {
      double mVal =  iMACD(NULL, 0, mMacdFast, mMacdSlow, mSignal, PRICE_CLOSE, 0, i);

      if(mVal >= 0)
       {
        mMacdU[i] = 1;
        mMacdD[i] = 0;
       }
      else 
       {
        mMacdU[i] = 0;
        mMacdD[i] = 1;
       }
     }

   return(0);
  }
//+------------------------------------------------------------------+
