Download MetaTrader 5
To add comments, please log in or register
Follow the news. View our company's official channel!
Paul
529
Paul 2015.12.10 18:09 

Can anyone show me how to place a VLine at the start of the day, for a specific time.  I am on EST and would like to show, on my chart, the start of the day.  Which is midnight.  My chart time is 5 hours ahead of EST.

        ObjectDelete("DayStart");     
        ObjectCreate("DayStart",OBJ_VLINE,0,Time[0],0); 
        ObjectSet("DayStart", OBJPROP_COLOR, Orange); 

Above is the code I generally use, for VLine.  I can change the value of Time[0] to a different bar number, but was hoping that there was a way to set VLine by time.


Thanks!

whroeder1
13641
whroeder1 2015.12.10 20:10  
Control Y does that for H1 and smaller charts.
Paul
529
Paul 2015.12.10 20:32  
Yes, but I want to show day beginning at midnight, EST, not 5:00 p.m.  EST. 
whroeder1
13641
whroeder1 2015.12.11 15:16  
/** This structure just contains static functions for name space control.     */
struct Date_Time{ // used in chart_time and utility
   #define SECONDS         int            ///< Difference between two datetimes.
   #define HR2400 86400 // PERIOD_D1 * 60 = 24 * 3600
static SECONDS    time(datetime when=0){
   return SECONDS((when == 0) ? TimeCurrent() : when) % HR2400;                }
static datetime   date(datetime when=0){
   return ((when == 0) ? TimeCurrent() : when) - time(when);                   }
static datetime   tomorrow( datetime when=0){
   return date((when == 0) ? TimeCurrent() : when) + HR2400;                   }
/// Returns previous trading day.
static datetime   yesterday(datetime when=0) /**< Previous relative to when.*/{
   if(when==0) when = TimeCurrent();
   // Make sure I have daily history.
   download_history(_Symbol, PERIOD_D1, __FUNCTION__);
   INDEX    iD1   = iBarShift(NULL, PERIOD_D1,  when);   // Find today.
   return iTime(NULL, PERIOD_D1, iD1 + 1);               // Return yesterday.
}
/// Converts a day of week to a string.
static string  as_string(ENUM_DAY_OF_WEEK dow,  ///<[in] Day of the week.
                         COUNT         nChar=9) /**<[in] Number of characters to
                                              * return, e.g.\ 3 outputs Sun. */{
   static const string  txt[] = {"Sunday",      "Monday",      "Tuesday",
                                 "Wednesday",   "Thursday",    "Friday",
                                 "Saturday"};
   return StringSubstr(txt[dow], nChar);
}
 private:
   char onebyte;///< Prevent "struct has no members, size assigned to 1 byte
};
:
#define EST5 -18000  // 5*3600
datetime chartNow      = Time[0];
datetime estNow        = chartNow + EST5;
datetime estMidnight   = Date_Time::date(estNow);
datetime chartMidnight = midnight - EST5;
ObjectDelete("DayStart");
ObjectCreate("DayStart",OBJ_VLINE,0,chartMidnight,0); 
Carl Schreiber
5959
Carl Schreiber 2015.12.11 17:05  

may be you just need (always today's 00:00 broker time):

ObjectCreate("DayStart",OBJ_VLINE,0,iTime(_Symbol,PERIOD_D1,0)+OffSet,0);
/
To add comments, please log in or register