#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrAqua
#property indicator_color2 clrMagenta

extern int   NumBar               = 500;
extern int   ArrDistance          = 15;
extern int   GapSize              = 20;
extern bool  DrawLineOrRectangle  = true;
extern bool  FillColorIfRectangle = false;
extern color TopLineColor         = clrAqua;
extern color BottomLineColor      = clrMagenta;
extern ENUM_LINE_STYLE LineStyle  = STYLE_DOT;
extern int   LineWidth            = 1;
       
double   up[],down[], close,open,a,b;
datetime TimeEnd   = Time[0]+Period()*240;
//+------------------------------------------------------------------+
int init() 
{  
   SetIndexBuffer(0, up);
   SetIndexStyle (0, DRAW_ARROW, EMPTY, 0);
   SetIndexArrow (0, 233);
   SetIndexBuffer(1, down);
   SetIndexStyle (1, DRAW_ARROW, EMPTY, 0);
   SetIndexArrow (1, 234);
   
   return (0);
}
//+------------------------------------------------------------------+
int deinit() 
{
  ObjectsDeleteAll(ChartID(),"Hi");
  ObjectsDeleteAll(ChartID(),"Lo");
  
 return (0);
}
//+------------------------------------------------------------------+
int start() 
{
   int limit = MathMin(NumBar,Bars-IndicatorCounted()-1);

   for (int i = 0; i <= limit; i++) 
   {
   close = Close[i + 1];  open  = Open[i];  a = 0;  b = 0;
   
      if (close < open) 
      {
         a = (open - close) / Point;
         if (a > GapSize) down[i] = High[i] + ArrDistance * Point; 
         if (a > GapSize) 
         {
         if ( DrawLineOrRectangle == true ) Pivot ("Lo",i,Time[i],High[i],  TimeEnd, BottomLineColor, LineStyle,   LineWidth); else
                                            //Pivot ("Lo",i,Time[i+1],Close[i+1],  TimeEnd, BottomLineColor, LineStyle,   LineWidth); else
                                            //Pivot2("Lo",i,Time[i],High[i],  TimeEnd,Close[i], BottomLineColor, LineStyle,   LineWidth);
                                            Pivot2("Lo",i,Time[i+1],Close[i+1],  TimeEnd,Open[i], BottomLineColor, LineStyle,   LineWidth);
         }
      }
      if (close > open) 
      {
         b = (close - open) / Point;
         if (b > GapSize) up[i] = Low[i] - ArrDistance * Point; 
         if (b > GapSize) 
         {
         if ( DrawLineOrRectangle == true ) Pivot ("Hi", i,Time[i],Low[i], TimeEnd, TopLineColor, LineStyle,  LineWidth); else
                                            //Pivot ("Hi", i,Time[i+1],Close[i+1], TimeEnd, TopLineColor, LineStyle,  LineWidth); else
                                            //Pivot2("Hi", i,Time[i],Low[i], TimeEnd,Close[i], TopLineColor, LineStyle,  LineWidth);
                                            Pivot2("Hi", i,Time[i+1],Close[i+1], TimeEnd,Open[i], TopLineColor, LineStyle,  LineWidth);
         }
      }
  }
   return (0);
}
//+------------------------------------------------------------------+
void Pivot(string Name, int i, datetime t1, double p1, datetime t2, color col,int sty ,int size)
{
   Name = Name+(string)i;
   ObjectDelete(Name);
   ObjectCreate(Name, OBJ_TREND, 0, t1, p1, t2, p1);
   ObjectSet(Name, OBJPROP_COLOR, col);
   ObjectSet(Name, OBJPROP_STYLE, sty);
   ObjectSet(Name, OBJPROP_WIDTH, size);
   ObjectSet(Name, OBJPROP_RAY, false);
   ObjectSet(Name, OBJPROP_BACK, true );
   ObjectSet(Name, OBJPROP_SELECTABLE, false );
}
//+------------------------------------------------------------------+
void Pivot2(string Name, int i, datetime t1, double p1, datetime t2, double p2 , color col,int sty ,int size)
{
   Name = Name+(string)i;
   ObjectDelete(Name);
   ObjectCreate(Name, OBJ_RECTANGLE, 0, t1, p1, t2, p2);
   ObjectSet(Name, OBJPROP_COLOR, col);
   ObjectSet(Name, OBJPROP_STYLE, sty);
   ObjectSet(Name, OBJPROP_WIDTH, size);
   ObjectSet(Name, OBJPROP_RAY, false); 
   if ( FillColorIfRectangle == true ) ObjectSet(Name, OBJPROP_BACK,true ); else  ObjectSet(Name, OBJPROP_BACK,false );
   ObjectSet(Name, OBJPROP_SELECTABLE, false );
}
//+------------------------------------------------------------------+