#property description "Stretch Candle finder"
#property link      "http://www.forexfactory.com/showthread.php?t=546796"
#property version   "15.061" //"150628.2011"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
#property indicator_label1  "Short_SC"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrAqua
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2
#property indicator_label2  "Long_SC"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrMagenta
#property indicator_style2  STYLE_SOLID
#property indicator_width2  2

input int maxHistory = 0;   //Max History (Bars)
input int minBody = 0;   //Min Body (Points)
input bool nooppositew = true;   //No Opposite wick
input bool nodoji = true;   //No Doji Candle


double ShortSCBuffer[];
double LongSCBuffer[];

int OnInit() {
   SetIndexBuffer(0, ShortSCBuffer);
   SetIndexBuffer(1, LongSCBuffer);
   SetIndexArrow(0, 159);//117
   SetIndexArrow(1, 159);
   
   
   return(INIT_SUCCEEDED);
}

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 countedbars;// = IndicatorCounted();
   if (maxHistory > 0)
      countedbars = MathMin(Bars , maxHistory);
   else  
      countedbars = Bars;                
                
   for(int i = countedbars - 1; i >= 0; i--) {      
      ShortSCBuffer[i] = EMPTY_VALUE;
      LongSCBuffer[i] = EMPTY_VALUE;
      if (nodoji && Close[i] == Open[i]) continue;
      if((MathAbs(Close[i]-Open[i]) < High[i] - MathMax(Close[i], Open[i]))
         && (!nooppositew || (nooppositew && MathMin(Close[i], Open[i]) == Low[i]))) {
         if (minBody == 0 || minBody * Point <= MathAbs(Close[i]-Open[i]))
            LongSCBuffer[i] = High[i] + MathAbs(Close[i]-Open[i]);
      }
      if((MathAbs(Close[i]-Open[i]) < MathMin(Close[i], Open[i]) - Low[i]) 
         && (!nooppositew || (nooppositew && MathMax(Close[i], Open[i]) == High[i]))) {
         if (minBody == 0 || minBody * Point <= MathAbs(Close[i]-Open[i]))
            ShortSCBuffer[i] = Low[i] - MathAbs(Close[i]-Open[i]);
      }      
   }
   return(rates_total);
}

void deinit() {
   ObjectsDeleteAll(0,0,OBJPROP_ARROWCODE);
}