//+------------------------------------------------------------------+
//|                                           Day_Of_Week_Lables.mq4 |
//|                             Copyright (c) 2016, Gehtsoft USA LLC | 
//|                                            http://fxcodebase.com |
//|                                   Paypal: https://goo.gl/9Rj74e  | 
//+------------------------------------------------------------------+
//|                                      Developed by : Mario Jemic  |                    
//|                                          mario.jemic@gmail.com   |
//|                   BitCoin : 15VCJTLaz12Amr7adHSBtL9v8XomURo9RF   |
//+------------------------------------------------------------------+

#property copyright "Copyright (c) 2016, Gehtsoft USA LLC"
#property link      "http://fxcodebase.com"
#property version "1.0"

#property indicator_chart_window

extern int    sizeTxt          = 8;
extern int    Offset_Hours     = 0;
extern bool   Show_Day_Date    = true;
extern string Comment0         = "-- Days of Week --";
extern string Monday_Name      = "MONDAY";
extern string Tuesday_Name     = "TUESDAY";
extern string Wednesday_Name   = "WEDNESDAY";
extern string Thursday_Name    = "THURSDAY";
extern string Friday_Name      = "FRIDAY";
extern string Saturday_Name    = "SATURDAY";
extern string Sunday_Name      = "SUNDAY";
extern string Comment1         = "-- Months of Year --";
extern string January_Name     = "January";
extern string February_Name    = "February";
extern string March_Name       = "March";
extern string April_Name       = "April";
extern string May_Name         = "May";
extern string June_Name        = "June";
extern string July_Name        = "July";
extern string August_Name      = "August";
extern string September_Name   = "September";
extern string October_Name     = "October";
extern string November_Name    = "November";
extern string December_Name    = "December";
extern string Comment2         = "-- Styling --";
extern color  Days_Label_Clr   = clrYellow;
extern color  Days_Sep_Color   = clrGreen;
extern int    Days_Sep_Style   = STYLE_DOT;
extern int    Days_Sep_Width   = 0;
extern color  Months_Label_Clr = clrRed;
extern color  Months_Sep_Color = clrRed;
extern int    Months_Sep_Style = STYLE_SOLID;
extern int    Months_Sep_Width = 2;

//+------------------------------------------------------------------+
int init()
   {
   return(0);
  }
  
//+------------------------------------------------------------------+
int deinit()
   {
   ObjectsDeleteAll();
   return(0);
  }
  
//+------------------------------------------------------------------+
int start(){
   
   int i;
   int counted_bars=IndicatorCounted();
   int limit = Bars-counted_bars-1;
   
   string Days[7];
   Days[0] = Sunday_Name;
   Days[1] = Monday_Name;
   Days[2] = Tuesday_Name;
   Days[3] = Wednesday_Name;
   Days[4] = Thursday_Name;
   Days[5] = Friday_Name;
   Days[6] = Saturday_Name;
   
   string Months[12];
   Months[0] = January_Name;
   Months[1] = February_Name;
   Months[2] = March_Name;
   Months[3] = April_Name;
   Months[4] = May_Name;
   Months[5] = June_Name;
   Months[6] = July_Name;
   Months[7] = August_Name;
   Months[8] = September_Name;
   Months[9] = October_Name;
   Months[10] = November_Name;
   Months[11] = December_Name;
   
   double pipSize = MarketInfo(Symbol(),MODE_POINT);
   if (MarketInfo("EURUSD",MODE_DIGITS)==5) pipSize=pipSize*10; // I take the EURUSD as an example to check if it is 5 digits instead of 4, if so, I multiply it by 10
   
   string Day_Date;
   
   for(i=limit; i>=0; i--){
      if (TimeToStr(Time[i],TIME_MINUTES)=="0"+Offset_Hours+":00"){
         
         if (Show_Day_Date) Day_Date = TimeDay(Time[i]); else Day_Date = "";
         
         // Day Separator
         Separator("S"+i, Time[i], Days_Sep_Color, Days_Sep_Width, Days_Sep_Style);
         // Day Label
         ObjectMakeText("Day"+i, Time[i]+(86400/2), iHigh(NULL,PERIOD_D1,iBarShift(NULL,PERIOD_D1,Time[i]))+(20*pipSize), Days[TimeDayOfWeek(Time[i])]+" "+Day_Date, Days_Label_Clr, "Arial", sizeTxt-1 );
         
         if (iTime(NULL,PERIOD_MN1,iBarShift(NULL,PERIOD_MN1,Time[i]))!=iTime(NULL,PERIOD_MN1,iBarShift(NULL,PERIOD_MN1,Time[i+1]))){
            // Month Separator
            Separator("SM"+i, Time[i], Months_Sep_Color, Months_Sep_Width, Months_Sep_Style);
            // Month Label
            ObjectMakeText("Month"+i, Time[i]+(86400/2), iHigh(NULL,PERIOD_D1,iBarShift(NULL,PERIOD_D1,Time[i]))+(30*pipSize), Months[TimeMonth(Time[i])-1], Months_Label_Clr, "Arial", sizeTxt );
         }
      }
   }
   
   return(0);
  }
//+------------------------------------------------------------------+

void Separator(string Nombre, datetime tiempo1, color sesscolor, int ancho, int style){
   ObjectDelete(Nombre);
   ObjectCreate(Nombre, OBJ_VLINE, 0, tiempo1, WindowPriceMax());
   ObjectSet(Nombre, OBJPROP_COLOR, sesscolor);
   ObjectSet(Nombre, OBJPROP_STYLE, style);
   ObjectSet(Nombre, OBJPROP_WIDTH, ancho);
   ObjectSet(Nombre, OBJPROP_BACK, True);
}

void ObjectMakeText( string nm, datetime tiempo1, double precio1, string Texto, color TColor, string Font = "ArialBlack", int FSize = 15){
   ObjectDelete(nm);
   ObjectCreate( nm, OBJ_TEXT, 0, tiempo1, precio1 );
   ObjectSetText( nm, Texto, FSize, Font, TColor );
   ObjectSet(nm, OBJPROP_TIME1, tiempo1);
   ObjectSet(nm, OBJPROP_PRICE1, precio1);
   return;
}