#property copyright "Copyright © 2015 0ll"
#property link      "email:   0ll@vipmail.ru"
#property description "Индикатор индикации свечного паттерна 3rdCandle для kashmarik подробно: http://forum.tradelikeapro.ru/index.php?topic=10203.0"
#property strict

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2

//--- indicator parameters
input  bool FilterBullBearCandle = false;

//--- indicator buffer
double UpArrow[], DownArrow[];

//+------------------------------------------------------------------+
int OnInit(void)
{
   IndicatorShortName("3rdCandle");
   IndicatorBuffers(2);
   IndicatorDigits(_Digits);
//--- check for input
//--- drawing settings
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, UpArrow);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, DownArrow);
   SetIndexEmptyValue(1,0.0);

return(INIT_SUCCEEDED);
}
int i;
//+------------------------------------------------------------------+
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[])
{
   i = (prev_calculated < 4) ? rates_total - prev_calculated-4-2 : rates_total - prev_calculated;
   if (i < 0) return(prev_calculated);

   while(i > 0)
   {
      if( High[i+1] > High [i] && High [i+1] > High [i+2] && 
          Low [i+1] > Low  [i] && Low  [i+1] > Low  [i+2] &&
          Open[i]   > Close[i] && Close[i+1] > Close[i] )
      {
         if ( FilterBullBearCandle && Open[i+1] <= Close[i+1] ) continue;
         DownArrow[i] = High[i+1] + 0.0003;
         Alert("3rdCandle: ",_Symbol," DownArrow");
      }
      if( High[i+1] < High [i] && High [i+1] < High[i+2] && 
          Low [i+1] < Low  [i] && Low  [i+1] < Low [i+2] &&
          Open[i]   < Close[i] && Close[i+1] < Close[i] )
      {
         if ( FilterBullBearCandle && Open[i+1] >= Close[i+1] ) continue;
         UpArrow[i] = Low[i+1] - 0.0003;  //High[i+1] - (High[i+1]-Low[i+1]);
         Alert("3rdCandle: ",_Symbol," UpArrow");
      }
      i--;
   }

return(rates_total);
}
