//+------------------------------------------------------------------+
//|                                              1-2-3-Go Arrows.mq4 |
//|              http://www.forexfactory.com/showthread.php?t=226581 |
//+------------------------------------------------------------------+
#property link      "http://www.forexfactory.com/showthread.php?t=226581"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

extern int Gap = 500;

double ExtMapBufferUp[];
double ExtMapBufferDown[];
double _gap;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
  SetIndexStyle(0,DRAW_ARROW, STYLE_SOLID,2);
  SetIndexArrow(0, SYMBOL_ARROWUP);
  SetIndexBuffer(0,ExtMapBufferUp);
  SetIndexStyle(1,DRAW_ARROW, STYLE_SOLID,2);
  SetIndexArrow(1, SYMBOL_ARROWDOWN);
  SetIndexBuffer(1,ExtMapBufferDown);
  
  _gap = Gap * Point;
  return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{

}

double GetCandleBodyHeight(int i)
{
  if(Close[i] > Open[i])
    return(Close[i] - Open[i]);
  else
    return(Open[i] - Close[i]);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
  int counted_bars=IndicatorCounted();
  int limit;
  limit=Bars-counted_bars;
  
  double candle0Height, candle1Height, candle2Height;

  for(int i=0; i<limit; i++)
  {
    candle0Height = GetCandleBodyHeight(i);
    candle1Height = GetCandleBodyHeight(i+1);
    candle2Height = GetCandleBodyHeight(i+2);
    
    if(Close[i] > MathMax(Close[i+1], Close[i+2]) &&
       candle0Height > MathMax(candle1Height, candle2Height) &&
       candle0Height < MathMin(candle1Height * 2, candle2Height * 2))
      ExtMapBufferUp[i] = Low[i] - _gap;
    else
      ExtMapBufferUp[i] = EMPTY_VALUE;
      
    if(Close[i] < MathMin(Close[i+1], Close[i+2]) &&
       candle0Height > MathMax(candle1Height, candle2Height) &&
       candle0Height < MathMin(candle1Height * 2, candle2Height * 2))
      ExtMapBufferDown[i] = High[i] + _gap;
    else
      ExtMapBufferDown[i] = EMPTY_VALUE;    
  }


  return(0);
}
//+------------------------------------------------------------------+