//+------------------------------------------------------------------+
//|                                             Tudor Morar - t3angle|
//+------------------------------------------------------------------+

//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 4
#property  indicator_color2  Red
#property  indicator_color3  Green

//---- indicator parameters
extern int pricetype=PRICE_CLOSE;
extern int maperiod=14;
//---- indicator buffers
double     MacdBuffer[];
double     Up[];
double     Down[];
double     MacdBuffer1[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings

   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);

   IndicatorDigits(Digits+1);
   SetIndexBuffer(0,MacdBuffer);
   SetIndexBuffer(1,Down);
   SetIndexBuffer(2,Up);
   SetIndexBuffer(3,MacdBuffer1);
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
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 buffer
   for(int i=0; i<limit; i++)
      MacdBuffer1[i]=iCustom(NULL,0,"T3_clean",maperiod,pricetype,0.618,"current time frame",i)-iCustom(NULL,0,"T3_clean",maperiod-1,pricetype,0.618,"current time frame",i+1);
    for( i=0; i<limit-1; i++)
      MacdBuffer[i]=MacdBuffer1[i]-MacdBuffer1[i+1];
    for( i=0; i<limit-2; i++)
    if (MacdBuffer[i]>0) {Up[i]=MacdBuffer[i]; Down[i]=EMPTY_VALUE;}
    else {Up[i]=EMPTY_VALUE; Down[i]=MacdBuffer[i];}
   return(0);
  }
 
//+------------------------------------------------------------------+