//+------------------------------------------------------------------+
//|                                       Copyright © 2009, fewhills |
//+------------------------------------------------------------------+
#property copyright "fewhills"
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_width1 2
#property indicator_width2 2

//---- buffers
double hi[];
double lo[];

extern int HowManyBarsToTheLeft = 5;

int i;

int BasePips(int input)
{
   int result = input;
   int resDig = Digits;
   
   if (resDig == 3 || resDig == 5) result *= 10;
   
   return (result);
}
  
int init()
  {

  IndicatorBuffers(2);
 
//---- drawing settings
   SetIndexArrow(0, 119);
   SetIndexArrow(1, 119);
   
   SetIndexStyle(0,DRAW_ARROW,STYLE_DOT,2,Red);
   SetIndexDrawBegin(0,HowManyBarsToTheLeft);
   SetIndexBuffer(0, hi);
   SetIndexLabel(0,"Reversal High");
    

   SetIndexStyle(1,DRAW_ARROW,STYLE_DOT,2,Blue);
   SetIndexDrawBegin(1,HowManyBarsToTheLeft);
   SetIndexBuffer(1, lo);
   SetIndexLabel(1,"Reversal Low");
  
   return(0);
  }

int start()
{
   i = Bars - HowManyBarsToTheLeft;
   
   while( i >= 0 )
   {
   
      if (Close[i] < Open[i] && barsToLeft(i, true))
      {
         hi[i] = High[i] + BasePips(10) * Point;
      }
      else
      {
         hi[i] = 0;
      }      
        
      if (Close[i] > Open[i] && barsToLeft(i, false))
      {
         lo[i] = Low[i] - BasePips(10) * Point;
      }
      else
      {
         lo[i] = 0;
      }
           
      i--;
   }   
   return(0);
}

bool barsToLeft(int k, bool top)
{
   bool Approved = true;
   
   if (HowManyBarsToTheLeft < 1) return (false);
   
   for (int j=0; j < HowManyBarsToTheLeft; j++)
   {
      if (top)
      {
         if (Approved) Approved = (High[k] > High[k+j+1]);
      }
      else
      {
         if (Approved) Approved = (Low[k] < Low[k+j+1]);
      }   
   }
   
   return (Approved);
} 
//+------------------------------------------------------------------+