//+------------------------------------------------------------------+
//|                                                    DayBorders.mq4 |
//|                                            Aleksandr Pak, Almaty |
//|                                                   ekr-ap@mail.ru |
//+------------------------------------------------------------------+
#property copyright " AP"
#property link      "ekr-ap@mail.ru"
//------------------------------------------------------------------+
//| _TRO_MODIFIED_VERSION                                  |
//| MODIFIED BY AVERY T. HORTON, JR. AKA THERUMPLEDONE@GMAIL.COM     |
//| I am NOT the ORIGINAL author 
//  and I am not claiming authorship of this indicator. 
//  All I did was modify it. I hope you find my modifications useful.|
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window

/*
Скрипт рисует границы предыдущего календарного дня.
Вертикальные линии предыдущего дня с фиксированными именами DayTimeOpen DayTimeClose
Горизонтальные линии с фиксированнымии именами DayOpen DayClose
Цвета линий устанавливаются при компиляции.
*/
/*
The script draws borders of the last calendar day.
Vertical lines of the last day with fixed names DayTimeOpen DayTimeClose
Horizontal lines with fixed names DayOpen DayClose
Colors of lines of borders are set at compilation.
*/

extern bool   show.vline = true ;

extern string noteTimeNY = " 14:00 server time = 05:00 mst" ; 
extern string noteTimeAU = " 23:00 server time = 14:00 mst" ; 
extern string noteTimeLD = " 09:00 server time = 00:00 mst" ; 


extern string myHHMM       = "23:00"; // 05:00 am pst = 14:00 server time 
extern string myMessage    = "Sydney" ; 
extern int    Line_Style   = STYLE_DOT ;

extern color color_Time=Yellow, color_DayOpen=Yellow ; //Set colors of lines


string Obj0001,Obj0002,Obj0003,Obj0004,Obj0005,Obj0006,Obj0007,Obj0008,Obj0009,Obj0010,Obj0011;  

string symbol, tChartPeriod,  tShortName, LabelTime ;  
int    digits, period  ; 
 
//+------------------------------------------------------------------+

int init()
{
   period       = Period() ;   
   tChartPeriod = TimeFrameToString(period) ;
   symbol       = Symbol() ;
   LabelTime    = symbol + tChartPeriod  ;  
   
   Obj0001 = "dayborders0001" + myMessage ;    
   Obj0002 = "dayborders0002" + myMessage ;     
   Obj0003 = "dayborders0003" + myMessage ;      
   Obj0004 = "dayborders0004" + myMessage ;    
   
   return(0);
}
  
//+------------------------------------------------------------------+

int deinit()
{

ObjectDelete(Obj0001); 
ObjectDelete(Obj0002); 
ObjectDelete(Obj0003);   
ObjectDelete(Obj0004);   
 
   return(0);
}
  
//+------------------------------------------------------------------+

int start()
{

int bars_count = WindowBarsPerChart() ;
int nHH        = Highest(NULL,0,MODE_HIGH,bars_count,0); 

int   yy = TimeYear(Time[0]);
int   mm = TimeMonth(Time[0]);
int   dd = TimeDay(Time[0]);  
   
string yymmddms = yy+"."+mm+"."+dd+" " + myHHMM ;
         
datetime var1 = StrToTime(yymmddms);  
   
datetime day=24*60*60;
datetime r= var1 ;

//datetime r=(TimeCurrent()/day)*day;
//datetime r=(var1/day)*day;

int      cd=iBarShift(NULL,0,r,FALSE);
datetime r2=r-day;


if(TimeDayOfWeek(r2)==0) r2=r2-day-day;
int cd2=iBarShift(NULL,0,r2,FALSE);

if( var1 > Time[0] ) { r = r2 ;cd = cd2 ;} // if date/time is greater than current date/time go back 1 day

if(show.vline)
{
   if(ObjectFind(Obj0001)==-1) {ObjectCreate  (Obj0001,OBJ_VLINE,0,r,0); }
   else                        {ObjectSet     (Obj0001,OBJPROP_TIME1,r); }
                   
   ObjectSet(Obj0001,OBJPROP_COLOR,color_Time);
   ObjectSet(Obj0001,OBJPROP_STYLE,Line_Style);
   ObjectSet(Obj0001,OBJPROP_BACK,true);
      
   if(ObjectFind(Obj0004)==-1) {ObjectCreate  (Obj0004,OBJ_VLINE,0,r2,0); }
   else                        {ObjectSet     (Obj0004,OBJPROP_STYLE,Line_Style); }
                   
   ObjectSet(Obj0004,OBJPROP_COLOR,color_Time);
   ObjectSet(Obj0004,OBJPROP_TIME1,r2)  ;
   ObjectSet(Obj0004,OBJPROP_BACK,true);
}   
            
if(ObjectFind(Obj0002)==-1) {ObjectCreate(Obj0002,OBJ_TREND,0,0,0,0); ObjectSet(Obj0002,OBJPROP_RAY,false); }         

ObjectSet(Obj0002,OBJPROP_COLOR,color_DayOpen);                            
ObjectSet(Obj0002,OBJPROP_STYLE,Line_Style);                              
ObjectMove(Obj0002,0,r,Open[cd]);
ObjectMove(Obj0002,1,Time[0],Open[cd]);       
                                                              
ObjectDelete(Obj0003); 
ObjectCreate(Obj0003,OBJ_TEXT,0,r,High[nHH]) ;  
ObjectSetText(Obj0003,myMessage, 10, "Times New Roman", color_Time) ;  

  
                                                                                                    
   return(0);
}


//+------------------------------------------------------------------+
 
string TimeFrameToString(int tf)
{
   string tfs;
   switch(tf) {
      case PERIOD_M1:  tfs="M1"  ; break;
      case PERIOD_M5:  tfs="M5"  ; break;
      case PERIOD_M15: tfs="M15" ; break;
      case PERIOD_M30: tfs="M30" ; break;
      case PERIOD_H1:  tfs="H1"  ; break;
      case PERIOD_H4:  tfs="H4"  ; break;
      case PERIOD_D1:  tfs="D1"  ; break;
      case PERIOD_W1:  tfs="W1"  ; break;
      case PERIOD_MN1: tfs="MN";
   }
   return(tfs);
}
 
//+------------------------------------------------------------------+

/*

        
Comment(

"r.... " , TimeToStr(r) , "\n" ,  
 

"") ;
         
ObjectSetText(Obj0003,myMessage, 10, "Times New Roman", color_Time) ; 
ObjectSet(Obj0003,OBJPROP_TIME1,r); 
ObjectSet(Obj0003,OBJPROP_PRICE1,High[nHH]);   // was High[cd]

string sTimeCurrent = TimeToStr(TimeCurrent() );
string svar1 = TimeToStr(var1 );
Comment(

"r.... " , r , "\n" ,  
"Server.... " , sTimeCurrent , "\n" ,
"yymmddms.... " , yymmddms , "\n" , 
"svar1.... " , svar1 , "\n" ,  

"") ;  

string sTimeCurrent = TimeToStr(TimeCurrent() );
string svar1 = TimeToStr(var1 );

Comment(

"r.... " , r , "\n" ,  
"Server.... " , sTimeCurrent , "\n" ,
"yymmddms.... " , yymmddms , "\n" , 
"svar1.... " , svar1 , "\n" ,  

"") ;

*/


