//------------------------------------------------------------------
#property copyright "Copyright 2017"
#property link      "mladenfx@gmail.com"
#property version   "1.00"
//------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1  clrDeepSkyBlue
#property indicator_type1   DRAW_LINE
#property indicator_style1  STYLE_DOT
#property strict

extern ENUM_TIMEFRAMES TimeFrame      = PERIOD_D1; // Time frame to use
extern int             TimeZoneOFData = 0;         // TimeZone
extern bool            Continued      = false;      // Show as continuous line?
double line[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------

int OnInit() { SetIndexBuffer(0, line); TimeFrame = MathMax(TimeFrame,_Period); return(0); }
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 counted_bars = prev_calculated;
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
           int limit=MathMin(rates_total-counted_bars,rates_total-1);

           for(int i=limit; i>=0; i--) 
               if (i<Bars-1)
                  if (iBarShift(NULL,TimeFrame,time[i]+TimeZoneOFData*3600)==iBarShift(NULL,TimeFrame,time[i+1]+TimeZoneOFData*3600))
                         line[i] =  line[i+1];
                  else { line[i] =  open[i]; if (!Continued && TimeFrame!=_Period) line[i+1] = EMPTY_VALUE; }
               else      line[i] =  open[i];
   return(rates_total);
}