//+------------------------------------------------------------------+
//|                                         Pinbar.mq4               |
//+------------------------------------------------------------------+
#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 clrYellow 
#property indicator_color2 clrMagenta 

#property indicator_width1 2 
#property indicator_width2 2 

extern int ArrowPosition = 5;
extern double WicksTimes = 4;

double Up_Arrow[];
double Down_Arrow[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexBuffer(0, Up_Arrow);
   SetIndexArrow(0, 233); 
   SetIndexLabel(0,"Up arrow");
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexBuffer(1, Down_Arrow);
   SetIndexArrow(1, 234); 
   SetIndexLabel(1,"Down arrow");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int i;                
   int Counted_bars;       
   Counted_bars=IndicatorCounted();
   i=Bars-Counted_bars;
   while(i>=0)             
   {      
      if (UpBar(i))
      {
         Up_Arrow[i] = Low[i] - (ArrowPosition * Point);
         Down_Arrow[i] = EMPTY_VALUE;
      }
      else if (DownBar(i))
      {
         Down_Arrow[i] = High[i] + (ArrowPosition * Point);
         Up_Arrow[i] = EMPTY_VALUE;
      }
      else
      {
         Up_Arrow[i] = EMPTY_VALUE;
         Down_Arrow[i] = EMPTY_VALUE;
      }
      i--;
   }
//----
   return(0);
}

bool UpBar(int j)
{  
   double top=MathMax(Close[j],Open[j]);
   double but=MathMin(Close[j],Open[j]);
   
   if(Close[j]>Open[j] && but-Low[j]>0 && but-Low[j]>WicksTimes*(High[j]-top))//; && (High[i]-top)>0 /*&& but-Low[i]>2*(top-but)*/)   
   {
      return (true);
   }
   return (false);
}

bool DownBar(int j)
{  
   double top=MathMax(Close[j],Open[j]);
   double but=MathMin(Close[j],Open[j]);
   
   if (Close[j]<Open[j] && High[j]-top>0 && High[j]-top>WicksTimes*(but-Low[j]))//;// && (but-Low[i])>0 /*&& High[i]-top>2*(top-but)*/)
   {
      return (true);
   }
   return (false);
}
//+------------------------------------------------------------------+