/*
Daily_High_Low_Close_Open_Middle_DK
Darkkiller
do not know who the first creator of this indicator.thanks to him
*/

#property copyright ""
#property link      ""

///+----Begin code---------+

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Yellow
#property indicator_color4 Goldenrod
#property indicator_color5 Goldenrod
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 4
#property indicator_width4 1
#property indicator_width5 1
double H=0;
double L=0;
double M=0;
double CL=0;
double OP=0;

extern int shift_time = 1;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {   
//---- indicators
   SetIndexLabel(0,"Daily High");
   SetIndexLabel(1,"Daily Low");
   SetIndexLabel(2,"Daily Middle");
   SetIndexLabel(3,"Daily Close");
   SetIndexLabel(4,"Daily Open");
   SetIndexStyle(0,DRAW_SECTION, 0,0);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_SECTION, 0,0);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_SECTION, 0,4);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_SECTION, 0,0);
   SetIndexBuffer(3,ExtMapBuffer4);
    SetIndexStyle(4,DRAW_SECTION, 0,0);
   SetIndexBuffer(4,ExtMapBuffer5);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   ObjectDelete("Prev-High");
   ObjectDelete("Prev-Low");
   ObjectDelete("Prev-Mid");
   ObjectDelete("Prev-Close");
   ObjectDelete("Prev-Open");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int pos = Bars-shift_time-1;
   int m = 0;
   int d = 0;
   int y = 0;
   string dt = "";
   datetime some_time = 0;
   int shift = 0;
   int tc = 0;
//----    
   if(Bars - counted_bars == 1) return(0);
   
   if( Bars < shift_time + 1 ) return(0);
   
   if (Period() < 1440)
   {
      tc = 1440;
   }else
   {
      switch (Period())
      {
      case 1440: 
         tc = 10080; 
         break;
      case 10080: 
         tc = 43200; 
         break;
      case 43200: 
         tc = 518400; 
         break;
      }
   }
  
   while(pos>=0)
   {
      m=TimeMonth(Time[pos]);
      d=TimeDay(Time[pos]);
      y=TimeYear(Time[pos]);
      dt = y + "." + m + "." + d + " 00:00";
      some_time = StrToTime(dt);
      
      //find the proper shift of the Daily bar having the same date as this timeframe's bar with the current shift
      shift = iBarShift(NULL,tc,some_time); 
      
      H = iHigh(NULL,tc,shift+shift_time);
      L = iLow(NULL,tc,shift+shift_time);
      M = (H+L)/2;
      CL = iClose(NULL,tc,shift+shift_time);
      OP = iOpen(NULL,tc,shift+shift_time);
           
      ExtMapBuffer1[pos] = H;
      ExtMapBuffer2[pos] = L; 
      ExtMapBuffer3[pos] = M;
      ExtMapBuffer4[pos] = CL;
      ExtMapBuffer5[pos] = OP;
      
      if(pos==0) CreateLabels();
      
      pos--;
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

void CreateLabels()

{
   if(ObjectFind("Prev-High")==-1)
   {
      ObjectCreate("Prev-High", OBJ_TEXT, 0, CurTime(), H);
      ObjectSetText("Prev-High","Daily High", 8, "Verdana", Silver);//each of the labels had letter, now blank
   }else {
      ObjectMove("Prev-High", 0, CurTime(), H);
   }      
      
   if(ObjectFind("Prev-Low")==-1)
   {
      ObjectCreate("Prev-Low", OBJ_TEXT, 0, Time[0], L);
      ObjectSetText("Prev-Low","Daily Low", 8, "Verdana", Silver);
   }else {
      ObjectMove("Prev-Low", 0, CurTime(), L);
   }
   
        if(ObjectFind("Prev-Mid")==-1)
   {
      ObjectCreate("Prev-Mid", OBJ_TEXT, 0, Time[0], M);
      ObjectSetText("Prev-Mid","Daily Middle", 8, "Verdana", Silver);
   }else {
      ObjectMove("Prev-Mid", 0, CurTime(), M);
   }

        if(ObjectFind("Prev-Close")==-1)
   {
      ObjectCreate("Prev-Close", OBJ_TEXT, 0, Time[0], CL);
      ObjectSetText("Prev-Close","Daily Close", 8, "Verdana", Silver);
   }else {
      ObjectMove("Prev-Close", 0, CurTime(), CL);
   }
   
    if(ObjectFind("Prev-Open")==-1)
   {
      ObjectCreate("Prev-Open", OBJ_TEXT, 0, Time[0], OP);
      ObjectSetText("Prev-Open","Daily Open", 8, "Verdana", Silver);
   }else {
      ObjectMove("Prev-Open", 0, CurTime(), OP);
   }
// Comment("Daily HLCOM ");   
   return(0);

}

