//+------------------------------------------------+
//| INDICATOR                         KeyTimes.mq4 |
//| MT4\experts\indicators\KeyTimes.mq4            |
//+------------------------------------------------+
#property copyright "Copyright © 2009 Robert Dee"

#define INDICATOR_VERSION    20090409
#define INDICATOR_NAME       "KeyTimes"

#property indicator_chart_window

extern int    KeyTime1      = 6;
extern string KeyTime1Label = "Zurich";

extern int    KeyTime2      = 7;
extern string KeyTime2Label = "London";

extern int    KeyTime3      = 14;
extern string KeyTime3Label = "Chicago";

extern int    KeyTime4      = 23;
extern string KeyTime4Label = "Rollover"; // Spot Forex Contract Rollovers

extern int    LabelDays     = 20;     // how many days to print the labels
extern color  LabelColor    = Gray;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName(INDICATOR_NAME);
SetIndexLabel(0,"");
for(int i=1; i <= LabelDays; i++)
   {
   ObjectDelete("_kt1_"+i);
   ObjectDelete("_kt2_"+i);
   ObjectDelete("_kt3_"+i);
   ObjectDelete("_kt4_"+i);
   ObjectCreate("_kt1_"+i, OBJ_TEXT, 0, 0, 0);
   ObjectCreate("_kt2_"+i, OBJ_TEXT, 0, 0, 0);
   ObjectCreate("_kt3_"+i, OBJ_TEXT, 0, 0, 0);
   ObjectCreate("_kt4_"+i, OBJ_TEXT, 0, 0, 0);
   ObjectSetText("_kt1_"+i, KeyTime1Label, 9, "Arial", LabelColor);
   ObjectSetText("_kt2_"+i, KeyTime2Label, 9, "Arial", LabelColor);
   ObjectSetText("_kt3_"+i, KeyTime3Label, 9, "Arial", LabelColor);
   ObjectSetText("_kt4_"+i, KeyTime4Label, 9, "Arial", LabelColor);
   } // end of for()
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
int    shift,hour,minute;
int    daycandles  = (3600*24)/(Time[0]-Time[1]);      // candles per day in this timeframe

shift = 0; // start with current (most recent) candle
for(int i=1; i <= LabelDays; i++)
   {
   while(shift < (i*daycandles))
      {
      hour = TimeHour(Time[shift]);
      minute = TimeMinute(Time[shift]);
      if(hour == KeyTime1 && minute == 0) ObjectMove("_kt1_"+i, 0, Time[shift], High[shift]+10*Point);
      if(hour == KeyTime2 && minute == 0) ObjectMove("_kt2_"+i, 0, Time[shift], High[shift]+10*Point);
      if(hour == KeyTime3 && minute == 0) ObjectMove("_kt3_"+i, 0, Time[shift], High[shift]+10*Point);
      if(hour == KeyTime4 && minute == 0) ObjectMove("_kt4_"+i, 0, Time[shift], High[shift]+10*Point);
      shift++; // move back one candle   
      } // end of while()
   } // end of for()

return(0); // end of start()
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
for(int i=1; i <= LabelDays; i++)
   {
   ObjectDelete("_kt1_"+i);
   ObjectDelete("_kt2_"+i);
   ObjectDelete("_kt3_"+i);
   ObjectDelete("_kt4_"+i);
   }
return(0);
}

