
#property version   "1.0"
#property strict

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red

string IndicatorName;
string IndicatorObjPrefix;

string GenerateIndicatorName(const string target)
{
   string name = target;
   int try = 2;
   while (WindowFind(name) != -1)
   {
      name = target + " #" + IntegerToString(try++);
   }
   return name;
}

double out[], Zero[];

int init()
{
   IndicatorName = GenerateIndicatorName("Time Counter Histogram");
   IndicatorObjPrefix = "__" + IndicatorName + "__";
   IndicatorShortName(IndicatorName);

   IndicatorBuffers(2);

   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(0, out);
   SetIndexLabel(0, "Time Counter");

   SetIndexStyle(1, DRAW_HISTOGRAM);
   SetIndexBuffer(1, Zero);

   return 0;
}

int deinit()
{
   ObjectsDeleteAll(ChartID(), IndicatorObjPrefix);
   return 0;
}

int start()
{
   if (Bars <= 1) 
      return 0;
   int ExtCountedBars = IndicatorCounted();
   if (ExtCountedBars < 0) 
      return -1;
   int limit = ExtCountedBars > 1 ? Bars - ExtCountedBars - 2 : Bars - 2;
   for (int pos = limit; pos >= 0; --pos)
   {
      out[pos] = Time[pos] - Time[pos + 1];
      Zero[pos] = 0;
   } 
   return 0;
}