//+------------------------------------------------------------------+
//|                                          (T_S_R)-DATA WINDOW.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property link      "Display by cja" 
// Thanks to the coders who supplied some of the code Daily_Open Indicator
// & Xdard777 for his MM labels code. 

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Coral
#property indicator_width1 2

//---- indicator buffers

#define Daily "Daily"
#define Daily1 "Daily1"
#define Daily2 "Daily2"

extern color DailyColor =Maroon;//C'99,39,11'
extern color DailyColor1 =DarkGreen;//C'0,49,09'
extern color DailyColor2= C'0,44,09';

double TodayOpenBuffer[];
extern int TimeZoneOfData= 0;
//---- buffers

//---- input parameters
int shift=0,i2=0,WorkTime=0,Periods=0,CurPeriod=0,nTime=0;
int nDigits;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName("TSR");
   /*if(Symbol()=="GBPJPY" || Symbol()=="EURJPY" || Symbol()=="USDJPY" || Symbol()=="GOLD" || Symbol()=="USDMXN") nDigits = 2;
   if(Symbol()=="GBPUSD" || Symbol()=="EURUSD" || Symbol()=="NZDUSD" || Symbol()=="USDCHF"  ||
   Symbol()=="USDCAD" || Symbol()=="AUDUSD" || Symbol()=="EURUSD" || Symbol()=="EURCHF"  || Symbol()=="EURGBP"
   || Symbol()=="EURCAD" || Symbol()=="EURAUD" )nDigits = 4;*/


IndicatorShortName("TSR");
  	SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
	//SetIndexBuffer(0,TodayOpenBuffer);
	SetIndexLabel(0,"Open");
	SetIndexEmptyValue(0,0.0); 
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
           
   ObjectDelete(Daily);
   ObjectDelete(DailyColor);
   ObjectDelete(Daily1);
   ObjectDelete(DailyColor1);
   ObjectDelete(Daily2);
   ObjectDelete(DailyColor2);
   
   ObjectsDeleteAll(0, OBJ_TEXT); 
   ObjectsDeleteAll(0, OBJ_LABEL); 
   
   Comment(""); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
 {
  int lastbar;
   int counted_bars= IndicatorCounted();
   
   if (counted_bars>0) counted_bars--;
   lastbar = Bars-counted_bars;	
   DailyOpen(0,lastbar);
CreateHL();
}

void CreateObj(string objName, double start, double end, color clr)
  {
  ObjectCreate(objName, OBJ_RECTANGLE, 0, iTime(NULL,1440,0), start, Time[0], end);
   ObjectSet(objName, OBJPROP_COLOR, clr);
   ObjectCreate(objName, OBJ_RECTANGLE, 0, iTime(NULL,1440,0), 0, Time[0],0);
   ObjectSet(objName, OBJPROP_COLOR, clr);
   
   }
   void DeleteObjects()
   {
   ObjectDelete(Daily);
   ObjectDelete(DailyColor);
   ObjectDelete(Daily1);
   ObjectDelete(DailyColor1);
   ObjectDelete(Daily2);
   ObjectDelete(DailyColor2);
   }
   void CreateHL()
   {
   DeleteObjects();
  double HI2 = iHigh(NULL,1440,0);
  double LOW2 = iLow(NULL,1440,0); 
  double HI3 = iHigh(NULL,1440,1);
  double LOW3 = iLow(NULL,1440,1);
  double HI4 = iHigh(NULL,1440,0);
  double LOW4 = iLow(NULL,1440,0);
  double HI5 = iHigh(NULL,1440,2);
  double LOW5 = iLow(NULL,1440,2);
  double HI6 = iHigh(NULL,1440,3);
  double LOW6 = iLow(NULL,1440,3);
  double HI7 = iHigh(NULL,1440,4);
  double LOW7 = iLow(NULL,1440,4);
  double HI8 = iHigh(NULL,1440,5);
  double LOW8 = iLow(NULL,1440,5);
  double HI9 = iHigh(NULL,1440,6);
  double LOW9 = iLow(NULL,1440,6);
  double HI10 = iHigh(NULL,1440,7);
  double LOW10 = iLow(NULL,1440,7);
  double HI11 = iHigh(NULL,1440,8);
  double LOW11 = iLow(NULL,1440,8);
  double HI12 = iHigh(NULL,1440,9);
  double LOW12 = iLow(NULL,1440,9);
  double HI13 = iHigh(NULL,1440,10);
  double LOW13 = iLow(NULL,1440,10);
  double HI14 = iHigh(NULL,1440,11);
  double LOW14 = iLow(NULL,1440,11);
  double HI15 = iHigh(NULL,1440,12);
  double LOW15 = iLow(NULL,1440,12);
  double HI16 = iHigh(NULL,1440,13);
  double LOW16 = iLow(NULL,1440,13);
  double HI17 = iHigh(NULL,1440,14);
  double LOW17 = iLow(NULL,1440,14);
  double HI18 = iHigh(NULL,1440,15);
  double LOW18 = iLow(NULL,1440,15);
  double HI19 = iHigh(NULL,1440,16);
  double LOW19 = iLow(NULL,1440,16);
  double HI20 = iHigh(NULL,1440,17);
  double LOW20 = iLow(NULL,1440,17);
  double HI21 = iHigh(NULL,1440,18);
  double LOW21 = iLow(NULL,1440,18);
  double HI22 = iHigh(NULL,1440,19);
  double LOW22 = iLow(NULL,1440,19);
  double HI23 = iHigh(NULL,1440,20);
  double LOW23 = iLow(NULL,1440,20);
  
  double OPEN = iOpen(NULL,1440,0);
  double CLOSE = iClose(NULL,1440,0);
  
  double ONE = (HI3-LOW3)/2;
  
  double FIVE = ((HI3-LOW3)+(HI5-LOW5)+(HI6-LOW6)+(HI7-LOW7)+(HI8-LOW8))/10;
                   
                
  double TEN = ((HI3-LOW3)+(HI5-LOW5)+(HI6-LOW6)+(HI7-LOW7)+(HI8-LOW8)+
                  (HI9-LOW9)+(HI10-LOW10)+(HI11-LOW11)+(HI12-LOW12)+(HI13-LOW13))/20;
                    
  double TWENTY = ((HI3-LOW3)+(HI5-LOW5)+(HI6-LOW6)+(HI7-LOW7)+(HI8-LOW8)+
               (HI9-LOW9)+(HI10-LOW10)+(HI11-LOW11)+(HI12-LOW12)+(HI13-LOW13)+
               (HI14-LOW14)+(HI15-LOW15)+(HI16-LOW16)+(HI17-LOW17)+(HI18-LOW18)+
               (HI19-LOW19)+(HI20-LOW20)+(HI21-LOW21)+(HI22-LOW22)+(HI23-LOW23))/40; 
                                              
  double AV = (ONE+FIVE+TEN+TWENTY)/4;// New Setting AV = (FIVE+TEN+TWENTY)/3;
  
  double HIDaily = iHigh(NULL,1440,0)-(AV);
  double LOWDaily = iLow(NULL,1440,0)+(AV);
  double HIDaily1 = iHigh(NULL,1440,0); 
  double LOWDaily1 =iLow(NULL,1440,0); 
  double HIDaily2 = iHigh(NULL,1440,0)-(AV)*2; 
  double LOWDaily2 =iLow(NULL,1440,0)+(AV)*2; 
   
  double CURRPRICE = iMA(Symbol(),0,1,0,MODE_EMA,PRICE_CLOSE,0); 
  
  string OpenLine = "";
  
  OpenLine= "OPEN";
  ObjectDelete(OpenLine); 
   ObjectCreate(OpenLine, OBJ_HLINE , 0,Time[0], OPEN);
   
   ObjectSet(OpenLine, OBJPROP_STYLE, STYLE_SOLID);
   ObjectSet(OpenLine, OBJPROP_COLOR,Black);
   ObjectSet(OpenLine, OBJPROP_WIDTH, 2);
                        
   /*string   Text="";
 
   Text =    "\n"  +"Open: " + DoubleToStr(OPEN,nDigits)+ "\n"  + "\n"+
            "Pips from Open: " + DoubleToStr((CLOSE-OPEN),nDigits)  + "\n" + "\n"+
            "From Hi To Low: " + DoubleToStr((HI2-LOW2),nDigits)  + "\n" + "\n"+
            "Today's Hi: " + DoubleToStr(HI2,nDigits)+ "\n" + "\n"+
            "TODAY's Low: " + DoubleToStr(LOW2,nDigits)+ "\n" +  "\n"+
            "Top Daily Range:  " + DoubleToStr(LOWDaily2,nDigits)+ "\n" + "\n"+
            "Bottom Daily Range: " + DoubleToStr(HIDaily2,nDigits)+ "\n"+ "\n"+
            "50% Daily Average;: " +DoubleToStr(AV,nDigits)+ "\n" + "\n"+
            "LONG Entry:  " + DoubleToStr(LOWDaily,nDigits)+ "\n" + "\n"+
            "SHORT Entry: " + DoubleToStr(HIDaily,nDigits)+ "\n"+ "\n"+
            "Profit LONG:  " + DoubleToStr(CURRPRICE-LOWDaily,nDigits)+ "\n" + "\n"+
            "Profit SHORT: " + DoubleToStr(HIDaily-CURRPRICE,nDigits)+ "\n" ;

    Comment(Text);*/
    

//Short Average
 if(ObjectFind("HIDaily1") != 0)
{
ObjectCreate("HIDaily1", OBJ_TEXT, 0, Time[0], HIDaily);
ObjectSetText("HIDaily1", "                        SHORT Entry", 9, "Verdana", Yellow);
}
else
{
ObjectMove("HIDaily1", 0, Time[0], HIDaily);
} 

//High Average
 if(ObjectFind("HIDaily2") != 0)
{
ObjectCreate("HIDaily2", OBJ_TEXT, 0, Time[0], LOWDaily);
ObjectSetText("HIDaily2", "                      LONG Entry", 9, "Verdana", Yellow);
}
else
{
ObjectMove("HIDaily2", 0, Time[0], LOWDaily);
}

//Today's High
 if(ObjectFind("HIDaily3") != 0)
{
ObjectCreate("HIDaily3", OBJ_TEXT, 0, Time[0], HI4);
ObjectSetText("HIDaily3", "            High ", 9, "Verdana", YellowGreen);
}
else
{
ObjectMove("HIDaily3", 0, Time[0], HI4);
}

//Todays Low 
 if(ObjectFind("HIDaily4") != 0)
{
ObjectCreate("HIDaily4", OBJ_TEXT, 0, Time[0], LOW4);
ObjectSetText("HIDaily4", "           Low ", 9, "Verdana", YellowGreen);
}
else
{
ObjectMove("HIDaily4", 0, Time[0], LOW4);
}

//Open
 if(ObjectFind("HIDaily5") != 0)
{
ObjectCreate("HIDaily5", OBJ_TEXT, 0, Time[2], OPEN);
ObjectSetText("HIDaily5", "Open", 9, "Verdana",SandyBrown);
}
else
{
ObjectMove("HIDaily5", 0, Time[2], OPEN);
}

//Bottom of Daily Range
 if(ObjectFind("HIDaily6") != 0)
{
ObjectCreate("HIDaily6", OBJ_TEXT, 0, Time[8],HIDaily2);
ObjectSetText("HIDaily6", "Bottom Daily Range", 9, "Verdana",SandyBrown);
}
else
{
ObjectMove("HIDaily6", 0, Time[8], HIDaily2);
}
//TOP of Daily Range
 if(ObjectFind("HIDaily7") != 0)
{
ObjectCreate("HIDaily7", OBJ_TEXT, 0, Time[7],LOWDaily2);
ObjectSetText("HIDaily7", "Top Daily Range", 9, "Verdana",SandyBrown);
}
else
{
ObjectMove("HIDaily7", 0, Time[7], LOWDaily2);
}

   {
if( (WorkTime != Time[0]) || (Periods != Period()) ) {
CreateObj(Daily, HIDaily, LOWDaily, DailyColor);
CreateObj(Daily1, HIDaily1, LOWDaily1, DailyColor1);
CreateObj(Daily2, HIDaily2, LOWDaily2, DailyColor2);}



   
        
        ObjectCreate("ATSR2", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR2","50% Average Daily Range:", 11, "Arial Narrow Bold", Silver);
        ObjectSet("ATSR2", OBJPROP_CORNER, 0);
        ObjectSet("ATSR2", OBJPROP_XDISTANCE, 5);
        ObjectSet("ATSR2", OBJPROP_YDISTANCE, 65);
        ObjectCreate("ATSR3", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR3",DoubleToStr(AV/Point,0),12, "Arial Bold", Orange);
        ObjectSet("ATSR3", OBJPROP_CORNER, 0);
        ObjectSet("ATSR3", OBJPROP_XDISTANCE, 150);
        ObjectSet("ATSR3", OBJPROP_YDISTANCE, 65);
        
        ObjectCreate("ATSR4", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR4","SHORT Entry:", 15, "Arial Narrow Bold", Tomato);
        ObjectSet("ATSR4", OBJPROP_CORNER, 0);
        ObjectSet("ATSR4", OBJPROP_XDISTANCE, 340);
        ObjectSet("ATSR4", OBJPROP_YDISTANCE, 40);
        ObjectCreate("ATSR5", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR5",DoubleToStr(HIDaily,Digits),20, "Arial Narrow Bold", Red);
        ObjectSet("ATSR5", OBJPROP_CORNER, 0);
        ObjectSet("ATSR5", OBJPROP_XDISTANCE, 470);
        ObjectSet("ATSR5", OBJPROP_YDISTANCE, 35);
        
       ObjectCreate("ATSR6", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR6","LONG Entry:", 15, "Arial Narrow Bold",YellowGreen);
        ObjectSet("ATSR6", OBJPROP_CORNER, 0);
        ObjectSet("ATSR6", OBJPROP_XDISTANCE, 340);
        ObjectSet("ATSR6", OBJPROP_YDISTANCE, 15);
        ObjectCreate("ATSR7", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR7",DoubleToStr(LOWDaily,Digits),20, "Arial Narrow Bold", Lime);
        ObjectSet("ATSR7", OBJPROP_CORNER, 0);
        ObjectSet("ATSR7", OBJPROP_XDISTANCE, 470);
        ObjectSet("ATSR7", OBJPROP_YDISTANCE, 10);
        
        ObjectCreate("ATSR8", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR8","Top Daily Average Range:", 15, "Arial Narrow Bold", YellowGreen);
        ObjectSet("ATSR8", OBJPROP_CORNER, 0);
        ObjectSet("ATSR8", OBJPROP_XDISTANCE, 5);
        ObjectSet("ATSR8", OBJPROP_YDISTANCE, 15);
        ObjectCreate("ATSR9", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR9",DoubleToStr(LOWDaily2,Digits),20, "Arial Narrow Bold", Lime);
        ObjectSet("ATSR9", OBJPROP_CORNER, 0);
        ObjectSet("ATSR9", OBJPROP_XDISTANCE, 240);
        ObjectSet("ATSR9", OBJPROP_YDISTANCE, 10);
        
        ObjectCreate("ATSR10", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR10","Bottom Average Daily Range:", 15, "Arial Narrow Bold",Tomato);
        ObjectSet("ATSR10", OBJPROP_CORNER, 0);
        ObjectSet("ATSR10", OBJPROP_XDISTANCE, 5);
        ObjectSet("ATSR10", OBJPROP_YDISTANCE, 40);
        ObjectCreate("ATSR11", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR11",DoubleToStr(HIDaily2,Digits),20, "Arial Narrow Bold", Red);
        ObjectSet("ATSR11", OBJPROP_CORNER, 0);
        ObjectSet("ATSR11", OBJPROP_XDISTANCE, 240);
        ObjectSet("aTSR11", OBJPROP_YDISTANCE, 35);
        
        ObjectCreate("ATSR12", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR12","Pips From HI to LOW:", 11, "Arial Narrow Bold", Silver);
        ObjectSet("ATSR12", OBJPROP_CORNER, 0);
        ObjectSet("ATSR12", OBJPROP_XDISTANCE, 320);
        ObjectSet("ATSR12", OBJPROP_YDISTANCE, 65);
        ObjectCreate("ATSR13", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR13",DoubleToStr((HI2-LOW2)/Point,0),12, "Arial Bold", Orange);
        ObjectSet("ATSR13", OBJPROP_CORNER, 0);
        ObjectSet("ATSR13", OBJPROP_XDISTANCE, 445);
        ObjectSet("ATSR13", OBJPROP_YDISTANCE, 65);
        
        ObjectCreate("ATSR14", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR14","OPEN:",11, "Arial Narrow Bold", Silver);
        ObjectSet("ATSR14", OBJPROP_CORNER, 0);
        ObjectSet("ATSR14", OBJPROP_XDISTANCE, 200);
        ObjectSet("ATSR14", OBJPROP_YDISTANCE, 65);
        ObjectCreate("ATSR15", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR15",DoubleToStr(OPEN,Digits),12, "Arial Bold", Orange);
        ObjectSet("ATSR15", OBJPROP_CORNER, 0);
        ObjectSet("ATSR15", OBJPROP_XDISTANCE, 240);
        ObjectSet("ATSR15", OBJPROP_YDISTANCE, 65);
        
        ObjectCreate("ATSR16", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR16","Profit LONG:", 15, "Arial Narrow Bold", YellowGreen);
        ObjectSet("ATSR16", OBJPROP_CORNER, 0);
        ObjectSet("ATSR16", OBJPROP_XDISTANCE, 570);
        ObjectSet("ATSR16", OBJPROP_YDISTANCE, 15);
        ObjectCreate("ATSR17", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR17",DoubleToStr(CURRPRICE-LOWDaily ,Digits),20, "Arial Narrow Bold", Lime);
        ObjectSet("ATSR17", OBJPROP_CORNER, 0);
        ObjectSet("ATSR17", OBJPROP_XDISTANCE, 690);
        ObjectSet("ATSR17", OBJPROP_YDISTANCE, 10);
        
        ObjectCreate("ATSR18", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR18","Profit SHORT:", 15, "Arial Narrow Bold", Tomato);
        ObjectSet("ATSR18", OBJPROP_CORNER, 0);
        ObjectSet("ATSR18", OBJPROP_XDISTANCE, 570);
        ObjectSet("ATSR18", OBJPROP_YDISTANCE, 40);
        ObjectCreate("ATSR19", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR19",DoubleToStr(HIDaily-CURRPRICE,Digits),20, "Arial Narrow Bold", Red);
        ObjectSet("ATSR19", OBJPROP_CORNER, 0);
        ObjectSet("ATSR19", OBJPROP_XDISTANCE, 690);
        ObjectSet("ATSR19", OBJPROP_YDISTANCE, 35);
        
        ObjectCreate("ATSR20", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR20",DoubleToStr(CURRPRICE,Digits),35, "Arial Narrow", Aqua);
        ObjectSet("ATSR20", OBJPROP_CORNER, 0);
        ObjectSet("ATSR20", OBJPROP_XDISTANCE, 780);
        ObjectSet("ATSR20", OBJPROP_YDISTANCE, 0);
        
         
        ObjectCreate("ATSR21", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR21","Daily HI:", 11, "Arial Narrow Bold", Silver);
        ObjectSet("ATSR21", OBJPROP_CORNER, 0);
        ObjectSet("ATSR21", OBJPROP_XDISTANCE, 495);
        ObjectSet("ATSR21", OBJPROP_YDISTANCE, 65);
        ObjectCreate("ATSR22", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR22",DoubleToStr(HI2,Digits),12, "Arial Bold", Orange);
        ObjectSet("ATSR22", OBJPROP_CORNER, 0);
        ObjectSet("ATSR22", OBJPROP_XDISTANCE, 547);
        ObjectSet("ATSR22", OBJPROP_YDISTANCE, 65);
        
         
        ObjectCreate("ATSR23", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR23","Daily LOW:", 11, "Arial Narrow Bold", Silver);
        ObjectSet("ATSR23", OBJPROP_CORNER, 0);
        ObjectSet("ATSR23", OBJPROP_XDISTANCE, 630);
        ObjectSet("ATSR23", OBJPROP_YDISTANCE, 65);
        ObjectCreate("ATSR24", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR24",DoubleToStr(LOW2,Digits),12, "Arial Bold", Orange);
        ObjectSet("ATSR24", OBJPROP_CORNER, 0);
        ObjectSet("ATSR24", OBJPROP_XDISTANCE, 695);
        ObjectSet("ATSR24", OBJPROP_YDISTANCE, 65);
        
         
        ObjectCreate("ATSR25", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR25","LocalTime:", 11, "Arial Narrow Bold", Silver);
        ObjectSet("ATSR25", OBJPROP_CORNER, 0);
        ObjectSet("ATSR25", OBJPROP_XDISTANCE, 785);
        ObjectSet("ATSR25", OBJPROP_YDISTANCE, 47);
        ObjectCreate("ATSR26", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR26",TimeToStr(LocalTime(),Digits-2),12, "Arial Bold", Orange);
        ObjectSet("ATSR26", OBJPROP_CORNER, 0);
        ObjectSet("ATSR26", OBJPROP_XDISTANCE, 850);
        ObjectSet("ATSR26", OBJPROP_YDISTANCE, 47);
        
         ObjectCreate("ATSR27", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR27","SeverTime:", 11, "Arial Narrow Bold", Silver);
        ObjectSet("ATSR27", OBJPROP_CORNER, 0);
        ObjectSet("ATSR27", OBJPROP_XDISTANCE, 785);
        ObjectSet("ATSR27", OBJPROP_YDISTANCE, 65);
        ObjectCreate("ATSR28", OBJ_LABEL, WindowFind("TSR"), 0, 0);
        ObjectSetText("ATSR28",TimeToStr(CurTime(),Digits-2),12, "Arial Bold", Orange);
        ObjectSet("ATSR28", OBJPROP_CORNER, 0);
        ObjectSet("ATSR28", OBJPROP_XDISTANCE, 850);
        ObjectSet("ATSR28", OBJPROP_YDISTANCE, 65);

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

int DailyOpen(int offset, int lastbar)
{
   int shift;
   int tzdiffsec= TimeZoneOfData * 3600;
   double barsper30= 1.0*PERIOD_M30/Period();
   bool ShowDailyOpenLevel= True;
   // lastbar+= barsperday+2;  // make sure we catch the daily open		 
   lastbar= MathMin(Bars-20*barsper30-1, lastbar);

	for(shift=lastbar;shift>=offset;shift--){
	  TodayOpenBuffer[shift]= 0;
     if (ShowDailyOpenLevel){
       if(TimeDayOfWeek(Time[shift]-tzdiffsec) != TimeDayOfWeek(Time[shift+1]-tzdiffsec)){      // day change
         TodayOpenBuffer[shift]= Open[shift];         
         TodayOpenBuffer[shift+1]= 0;                                                           // avoid stairs in the line
       }
       else{
         TodayOpenBuffer[shift]= TodayOpenBuffer[shift+1];
       }
	  }
   }
      return(0);
}