Redraw objects after 24hrs

 

I have an indicator that draws a box around the working hours candles of a chart.

It needs to reset itself every hour between the hours of 1900 and 0600. How could I do this with some code?

Do I have to simply run the delete objects code every hour and the start function will simply redraw everything?


//+------------------------------------------------------------------+
//|                                             The Box Breakout.mq4 |
//|                                             Copyright © 2007, SF |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, NY Forex Team"
#property link      ""


//#property indicator_separate_window
#property indicator_chart_window

extern string IIIIIIIIIII  = "<<<<< Box >>>>>";   // Hora de cierre
extern string BoxEnd       = "06:00";   // Hora de cierre
extern int BoxLenght       = 10;
extern string IIIIIIIIII   = "<<<<< Trade >>>>>";   // Hora de cierre
extern int Margin          = 3;
extern int TP1             = 15;
extern int TP2             = 30;
extern int TP3             = 45;
//extern int SL              = 30;

extern string IIIIIIIIIIII   = "<<<<< Box look >>>>>";   // Hora de cierre
extern color  BoxColor     = LightGoldenrod;      // color
extern bool   ShowPrice    = True;      // Muestra el precio?
extern color  clFont       = White;      // color de fondo
extern int    SizeFont     = 10;         // Tamaño
extern int    OffSet       = 4;        // Ñìåùåíèå


double   top, bottom;
datetime left, right, daybegin, dayend, t3, t4, t99;
string   boxdaybegin, boxbegin, boxdayend, dhc, dhf;
int      b1, b2;

int init()
  {

   IndicatorShortName("Working Hours");
   
   return(0);
  }


void deinit() 
{
    
  ObjectsDeleteAll (0,OBJ_HLINE);
  ObjectsDeleteAll (0,OBJ_VLINE);
  ObjectsDeleteAll (0,OBJ_LABEL);
  ObjectsDeleteAll (0,OBJ_RECTANGLE);
  ObjectsDeleteAll (0,OBJ_TEXT);
  ObjectsDeleteAll (1,OBJ_LABEL);

  
  Comment("");
}

// crea box
int start()
  {
  
   right = StrToTime (TimeToStr (TimeCurrent(),TIME_DATE) + " " + BoxEnd);

   if (right > TimeCurrent())
      {
         right = StrToTime (TimeToStr (TimeCurrent()- D'1970.01.01 23:59:59',TIME_DATE) + " " + BoxEnd);
      }


// si empieza en domingo suma 1 hora para comenzar a las 00 del lunes

   if (TimeDayOfWeek (right)==0)
      { 
         t99   = StrToTime (TimeToStr  (TimeCurrent()- D'1970.01.01 23:59:59',TIME_DATE) + " " + BoxEnd )  ;
         right = StrToTime (TimeToStr ( t99 + D'1970.01.01 1')); 
      }
      
      



   left = StrToTime (TimeToStr ( right - D'1970.01.01 1'* BoxLenght )); 
   
  
  
// si el box finaliza durante el weekend, se extiende para cerrar el viernes
   
   if (TimeDayOfWeek (left) == 0) 
      { 
      left = StrToTime (TimeToStr ( right - D'1970.01.01 1'* (BoxLenght +48) )); 
      }
      
      

      
   b1=iBarShift(NULL, 0, left);
   b2=iBarShift(NULL, 0, right);

  
  
   top = High [iHighest(NULL,0, MODE_HIGH,b1-b2, b2)];
   bottom=Low [Lowest (NULL, 0, MODE_LOW , b1-b2, b2)];
  

  ObjectCreate ("Box", OBJ_RECTANGLE,0,left, top, right,bottom);
  ObjectSet ("Box", OBJPROP_BACK, true);
  ObjectSet ("Box", OBJPROP_COLOR, BoxColor);
  
  
  ObjectCreate ("top",OBJ_HLINE, 0, 0,top);
  ObjectSet("top", OBJPROP_STYLE, STYLE_SOLID);
  ObjectSet("top", OBJPROP_COLOR,OrangeRed );
  ObjectMove("top",top, Time[0],top );
  
  ObjectCreate ("bottom",OBJ_HLINE, 0, 0,bottom);
  ObjectSet("bottom", OBJPROP_STYLE, STYLE_SOLID);
  ObjectSet("bottom", OBJPROP_COLOR,OrangeRed );
  ObjectMove("bottom",bottom, Time[0],bottom );

/// Calculo de entradas 

double bep, btp1, btp2, btp3, btp4, bsl;
double sep, stp1, stp2, stp3, stp4, ssl;
double drange;

   bep  = top+ (Margin * Point);
   btp1 = bep+TP1*Point;
   btp2 = bep+TP2*Point; 
   btp3 = bep+TP3*Point;
   btp4 = btp3+25*Point;
   bsl  = bottom;
//   bsl  = bep-SL*Point; 
  
   sep  = bottom-Margin*Point;
   stp1 = sep-TP1*Point;
   stp2 = sep-TP2*Point; 
   stp3 = sep-TP3*Point;
   stp4 = stp3-25*Point;
   ssl  = top;
//   ssl  = sep+SL*Point; 

   drange = (top-bottom)/Point;



// Lineas

  ObjectCreate ("BAT",OBJ_HLINE, 0, 0,bep);
  ObjectSet("BAT", OBJPROP_STYLE, STYLE_SOLID);
  ObjectSet("BAT", OBJPROP_COLOR,SpringGreen );
  ObjectMove("BAT",bep, Time[0],bep );
  


   return(0);
  }
 
anyone?
Reason: