#property copyright "Copyright © 2007, Systrader"
#property link "http://www...."
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Red
#property indicator_width1 2
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double Macd[];
double Signal[];
double UpArrow[];      // --added
double DnArrow[];      // --added
//---- counter
int counter;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_ARROW);    // --added
SetIndexStyle(3,DRAW_ARROW);    // --added
SetIndexArrow(2,233);
SetIndexArrow(3,234);
SetIndexDrawBegin(1,SignalSMA);
IndicatorDigits(Digits+1);
//---- indicator buffers mapping
SetIndexBuffer(0,Macd);
SetIndexBuffer(1,Signal);
SetIndexBuffer(2,UpArrow);     // --added
SetIndexBuffer(3,DnArrow);     // --added
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACDZC("+FastEMA+","+SlowEMA+" ,"+SignalSMA+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
ArrayInitialize(UpArrow,EMPTY_VALUE);   // --added
ArrayInitialize(DnArrow,EMPTY_VALUE);   // --added
//---- initialization done
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++)
  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 buffer
for(i=0; i<limit; i++)
   Signal[i]=iMAOnArray(Macd,Bars,SignalSMA,0,MODE_SMA,i);

// -- new logic to populate UpArrow, DnArrow buffers:
int cntup,cntdn = 0;
for(i=limit-2; i>=0; i--)
{
  if (Macd[i] > 0)
  {
    cntdn=0;
    cntup++;
    if (cntup == 3) UpArrow[i] = -0.0002;
  }  
  if (Macd[i] < 0)
  {
    cntup=0;
    cntdn++;
    if (cntdn == 3) DnArrow[i] = 0.0002;
  }  
}

//---- done
return(0);
}
//+------------------------------------------------------------------+

