//+------------------------------------------------------------------+
//|                                         MACD_Complete_Arrows.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_chart_window

#property  indicator_buffers 2
#property  indicator_color1  Lime
#property  indicator_color2  Magenta
#property indicator_width1 2
#property indicator_width2 2

//---- indicator parameters
extern string MACD_Setting   =  "<---- MACD Setting -----> ";
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalEMA=9;

extern string Arrows   =  "<---- Arrows Setting -----> ";
extern int arrow_pips_distance=10;
extern int arrow_code_up=217;
extern int arrow_code_down=218;
extern color arrow_color_up=Lime;
extern color arrow_color_down=Magenta;
extern int arrow_width=2;

double up_buffer[];
double dn_buffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   IndicatorBuffers(2);
   SetIndexBuffer(0,up_buffer);
   SetIndexBuffer(1,dn_buffer);
   
   SetIndexStyle(0, DRAW_ARROW,arrow_color_up,arrow_width);
   SetIndexArrow(0, arrow_code_up);
   SetIndexStyle(1, DRAW_ARROW,arrow_color_down,arrow_width);
   SetIndexArrow(1, arrow_code_down);
   
   SetIndexLabel(0,"MACD Up Arrow");
   SetIndexLabel(1,"MACD Down Arrow");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for(int i=0; i<limit; i++)
   {
      double macd_up1=iCustom(Symbol(),0,"MACD_Complete", FastEMA, SlowEMA, SignalEMA,1,i);
      double macd_dn1=iCustom(Symbol(),0,"MACD_Complete", FastEMA, SlowEMA, SignalEMA,2,i);
      
      double macd_up2=iCustom(Symbol(),0,"MACD_Complete", FastEMA, SlowEMA, SignalEMA,1,i+1);
      double macd_dn2=iCustom(Symbol(),0,"MACD_Complete", FastEMA, SlowEMA, SignalEMA,2,i+1);
   
      if(macd_up1>macd_dn1 && macd_up2<=macd_dn2)
      {
         up_buffer[i]=iLow(Symbol(),0,i)- (arrow_pips_distance*Point);
         dn_buffer[i]=EMPTY_VALUE;
      }
      else if(macd_up1<macd_dn1 && macd_up2>=macd_dn2)
      {
         dn_buffer[i]=iHigh(Symbol(),0,i)+ (arrow_pips_distance*Point);
         up_buffer[i]=EMPTY_VALUE;
      }
      else
      {
         up_buffer[i]=EMPTY_VALUE;
         dn_buffer[i]=EMPTY_VALUE;
      }
   }
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+