//+------------------------------------------------------------------+
//|                                                        50perc.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue


double UP[];


bool NewDay=false; int k; int barshift;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer(0,UP);                   // Assigning an array to a buffer
   SetIndexStyle (0,DRAW_LINE, STYLE_DOT,1);  // line style

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int  i;                          // Bar index
   int Counted_bars=IndicatorCounted(); // Number of counted bars
   i=Bars-Counted_bars-1;
   
   while(i>=0)                      // Loop for uncounted bars
     {
      k=i;date();
      if (NewDay==true)
        {
         double PrevLow= iLow(NULL,1440,barshift+1);
         double PrevHigh= iHigh(NULL,1440,barshift+1);
         double range= (PrevHigh - PrevLow)/2;
         UP[i]= iLow(NULL,1440,barshift+1)+range;         
         UP[i+1]=EMPTY_VALUE;  
        }else {
               UP[i]= UP[i+1];               
              }         

      i-- ;
     } 
   
   
   
   
   
   
   
   return(0);
   
   
   
   
  }
//+------------------------------------------------------------------+
// giorno e ora:
  void date()
 {  
      double tempo= Time[k];
      static int giorno= 10;
      NewDay=false;
      if(TimeDayOfWeek(tempo) != giorno)
        {
         giorno= TimeDayOfWeek(tempo);
         NewDay=true;
         barshift=iBarShift(NULL,1440,tempo);
        }  
 }