//+------------------------------------------------------------------+
//|                                        3 Consecutive Candles.mq4 |
//|                                  Copyright © 2006, Elton Treloar |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Elton Treloar"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
//---- input parameters
extern int       SignalPipsFromBottom=70;
extern int       SignalPipsFromTop=70;
extern int       DeSensitivityPips=0;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,217);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,NULL);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,218);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,NULL);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   
   if(counted_bars<0) return(-1);
   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   int limit=Bars-counted_bars;
   // ******************************************************************************************
   // ******************************************************************************************
   //                                        Main Loop                                      
   // ******************************************************************************************
   // ******************************************************************************************
   
   for(int i=0; i<limit; i++)
     {
         ExtMapBuffer1[i]=NULL;
         ExtMapBuffer2[i]=NULL;

         if(High[i]>(High[i+1]+DeSensitivityPips*Point) && High[i+1]>(High[i+2]+DeSensitivityPips*Point))   //Last two candles have higher highs.
            {
               if(Low[i]>Low[i+1]+DeSensitivityPips*Point && Low[i+1]>Low[i+2]+DeSensitivityPips*Point)  //Last two candles have had higher lows.
                  {
                     ExtMapBuffer1[i]=Low[i]-SignalPipsFromBottom*Point;
                  }
            } 
            
         if(Low[i]<Low[i+1]-DeSensitivityPips*Point && Low[i+1]<Low[i+2]-DeSensitivityPips*Point)   //Last two candles have higher highs.
            {
               if(High[i]<High[i+1]-DeSensitivityPips*Point && High[i+1]<High[i+2]-DeSensitivityPips*Point)  //Last two candles have had higher lows.
                  {
                     ExtMapBuffer2[i]=High[i]+SignalPipsFromBottom*Point;
                  }
            } 
     }
   return(0);
  }
//+------------------------------------------------------------------+