

#property indicator_chart_window
#property description "Draw Your Rectangle or box and this will extend it" 
input string GridSpace_Info = "Amount to extend past the current candle...";
input int Extend=2;

bool isInitialized = false;
datetime lastUpdateTime;

void DoWork()
{
   datetime now = TimeLocal();
   if (now - lastUpdateTime >= 5)
   {
      for (int i = ObjectsTotal(0) - 1; i >= 0; i--)
      {
         string name = ObjectName(0, i);
         long type = ObjectGetInteger(0, name, OBJPROP_TYPE);
         if (type == OBJ_RECTANGLE)
         {
            ObjectSetInteger(0, name, OBJPROP_TIME, iTime(_Symbol, (ENUM_TIMEFRAMES)_Period, 0) + Extend * 5000);
         }
      }

      lastUpdateTime = now;
   }

   if (!isInitialized)
   {
      EventSetTimer(5);
      isInitialized = true;
   }
}

void OnTimer()
{
   DoWork();
}

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[])
{
   return rates_total;
}

void init()
{
   DoWork();
}

void deinit()
{
   isInitialized = false;
}
