//+------------------------------------------------------------------+
//|                                            Market_Open_Lines.mq4 |
//|                        Copyright © 2011, Hesam.Akhavan@yahoo.com |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property copyright "Copyright © 2011, Hesam.Akhavan@yahoo.com"
#property link      "Hesam.Akhavan@yahoo.com"
extern int BorokerGmtShift=2;
extern string   Sydney_Open    = "22:00";
extern string   Tokyo_Open     = "23:00";
extern string   FrankFurt_Open    = "06:00";
extern string   London_Open     = "07:00";
extern string   NY_Open    = "12:00";
extern string   NYSE_Open        = "13:30";
extern string   Close_time="17:45";
extern string   shadowZones="************************";
extern string   startZone1="06:00";
extern string   endZone1="09:15";
extern string   startZone2="13:00";
extern string   endZone2="15:00";
extern int      NumberOfDays  = 10;
extern color    LineColor      = SlateGray;
extern color    ZoneColor      = C'25,25,25';
extern int      LabelPipOffset = 50;
extern int      LabelFontSize  = 9;
//extern string   For_Setting_Up="Hesam.Akhavan@yahoo.com";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
	return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
	/* Delete our objects */
	for(int i=0;i<NumberOfDays;i++)
	{
   ObjectDelete("SydOpen"+DoubleToStr(i,0));
	ObjectDelete("SydOpen"+DoubleToStr(i,0)+"_Label");
	ObjectDelete("TokOpen"+DoubleToStr(i,0));
	ObjectDelete("TokOpen"+DoubleToStr(i,0)+"_Label");
	
	ObjectDelete("FrankFurtOpen"+DoubleToStr(i,0));
	ObjectDelete("FrankFurtOpen"+DoubleToStr(i,0)+"_Label");
	ObjectDelete("LondonOpen"+DoubleToStr(i,0));
	ObjectDelete("LondonOpen"+DoubleToStr(i,0)+"_Label");
	ObjectDelete("NYOpen"+DoubleToStr(i,0));
	ObjectDelete("NYOpen"+DoubleToStr(i,0)+"_Label");
	ObjectDelete("NYSEOpen"+DoubleToStr(i,0));
	ObjectDelete("NYSEOpen"+DoubleToStr(i,0)+"_Label");
	ObjectDelete("zone1"+DoubleToStr(i,0));
	ObjectDelete("zone2"+DoubleToStr(i,0));	
	ObjectDelete("Closing Time"+DoubleToStr(i,0));
	ObjectDelete("Closing Time"+DoubleToStr(i,0)+"_Label");
	}
	return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   /* If period > 1hr, don't draw open lines */
   if (Period() > PERIOD_H1) return(0);
   
   /* Draw the market open lines */
   for(int i=0;i<NumberOfDays;i++)
   {
   DrawOpenLine("SydOpen"+DoubleToStr(i,0),"Sydney Open",Sydney_Open,i);
   DrawOpenLine("TokOpen"+DoubleToStr(i,0),"Tokyo Open",Tokyo_Open,i);

   DrawOpenLine("FrankFurtOpen"+DoubleToStr(i,0),"FrankFurt Open",FrankFurt_Open,i);
   DrawOpenLine("LondonOpen"+DoubleToStr(i,0),"London Open",London_Open,i);
   DrawOpenLine("NYOpen"+DoubleToStr(i,0),"NY Open",NY_Open,i);
   DrawOpenLine("NYSEOpen"+DoubleToStr(i,0),"NYSE Open",NYSE_Open,i);
   DrawOpenLine("Closing Time"+DoubleToStr(i,0),"Closing Time",Close_time,i);

   string OpenTime=FrankFurt_Open;
   datetime t1 =StrToTime(TimeHour(StrToTime(startZone1))+BorokerGmtShift+":"+TimeMinute(StrToTime(startZone1)))-i*86400;
   datetime t2 =StrToTime(TimeHour(StrToTime(endZone1))+BorokerGmtShift+":"+TimeMinute(StrToTime(endZone1)))-i*86400;
   ObjectCreate("zone1"+DoubleToStr(i,0),OBJ_RECTANGLE,0,t1,0,t2,10000);
   ObjectSet("zone1"+DoubleToStr(i,0),OBJPROP_BACK,true);
   ObjectSet("zone1"+DoubleToStr(i,0),OBJPROP_COLOR,ZoneColor);

   OpenTime=NYSE_Open;
    t1 =StrToTime(TimeHour(StrToTime(startZone2))+BorokerGmtShift+":"+TimeMinute(StrToTime(startZone2)))-i*86400;
    t2 =StrToTime(TimeHour(StrToTime(endZone2))+BorokerGmtShift+":"+TimeMinute(StrToTime(endZone2)))-i*86400;
   ObjectCreate("zone2"+DoubleToStr(i,0),OBJ_RECTANGLE,0,t1,0,t2,10000);
   ObjectSet("zone2"+DoubleToStr(i,0),OBJPROP_BACK,true);
   ObjectSet("zone2"+DoubleToStr(i,0),OBJPROP_COLOR,ZoneColor);
   
   }   
   return(0);
}
//+------------------------------------------------------------------+
void DrawOpenLine(string ObjName, string ObjText, string OpenTime,int i)
{
   /* Convert the open time string to datetime */
   int h=TimeHour(StrToTime(OpenTime))+BorokerGmtShift;
   if(h>=24) h-=24;
   datetime t =StrToTime(h+":"+TimeMinute(StrToTime(OpenTime)))-i*86400;
   
   /* Create the vertical open line */
   ObjectCreate(ObjName,OBJ_VLINE,0,t,0);
   ObjectSet(ObjName,OBJPROP_BACK,true); 
   ObjectSet(ObjName,OBJPROP_COLOR,LineColor);
   ObjectSet(ObjName,OBJPROP_STYLE,STYLE_DOT);
   
   /* Determine the vertical position of the label object */
   double p = High[iHighest(NULL,0,MODE_HIGH,WindowBarsPerChart(),1)];
   p = p-(LabelPipOffset*Point);
   
   /* Draw the label object */
   ObjectDelete(ObjName+"_Label");   
   ObjectCreate(ObjName+"_Label",OBJ_TEXT,0,t,p);
   ObjectSetText(ObjName+"_Label",ObjText,LabelFontSize);
   ObjectSet(ObjName+"_Label",OBJPROP_ANGLE,90);
   ObjectSet(ObjName+"_Label",OBJPROP_COLOR,LineColor);
//   ObjectMove(ObjName+"_Label",0,t,p);

   return(0);
}
//+------------------------------------------------------------------+