//+------------------------------------------------------------------+
//|                                                           SS.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters

//---- buffers
double UpBuff[];
double DownBuff[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,UpBuff);
   SetIndexBuffer(1,DownBuff);
//---- drawing settings
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,233);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,234);
//---
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
//---- initialization done   
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   int i=prev_calculated;
   int end=rates_total-5;
   int rare = 0;
   while(i<end)
     {
      if((high[i+1]>high[i+3] && high[i+3]>high[i+5]) || 
         (high[i+3]>high[i+4] && high[i+4]>high[i+5]) || 
         (high[i+1]>high[i+2] && high[i+2]>high[i+3]) || 
         (high[i+2]>high[i+3] && high[i+3]>high[i+4]) || 
         (low[i+1]<low[i+3] && low[i+3]<low[i+5]) || 
         (low[i+3]<low[i+4] && low[i+4]<low[i+5]) || 
         (low[i+1]<low[i+2] && low[i+2]<low[i+3]) || 
         (low[i+2]<low[i+3] && low[i+3]<low[i+4]))
        {
         rare=1;
        }

      if(rare==0)
        {
         if(open[i+1]<close[i+1])
           {
            UpBuff[i]=low[i+1];
           }
         else
           {
            DownBuff[i]=high[i+1];
           }
        }
        
        rare = 0;
      i++;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
