OBJ_VLINE - page 3

 

Thanks a lot Marco for the help ,  for some reason its working 

I configured the time in the D' format , then displayed that information as an alert , which you can see matches the arrow times however 

the V-Line is still created on the current candle .. see screen shot 


This is the code I used 

ObjectDelete(0,"v_line1");
         ObjectDelete(0,"v_line2");
        
        
         datetime TimeExit_SymSymbol = (datetime) ObjectGetInteger(0, Exit_SymSymbol, OBJPROP_TIME1);
         MqlDateTime str1;
         TimeToStruct(TimeExit_SymSymbol,str1);
         int Year = str1.year;
         int Month = str1.mon;
         int Day = str1.day;
         int Hour = str1.hour;
         int Minutes = str1.min;
         int Seconds = str1.sec;
        
         string V1DateString= "D'"+str1.year+"."+str1.mon+"."+str1.day+" "+ str1.hour+":" + str1.min+"'";//+":"+str1.sec+"'";
         
         ObjectCreate(0, "v_line1", OBJ_VLINE, 0, V1DateString, High[0]);
         ObjectCreate(0, "v_line2", OBJ_VLINE, 0, StringToTime(V1DateString), High[0]);
         Alert(V1DateString);


 
Here is a related topic: https://www.mql5.com/en/forum/233876
Vline 50 bars after the current time/bar
Vline 50 bars after the current time/bar
  • 2018.03.31
  • www.mql5.com
Hi there, I come to you to ask you : How can i draw a VLINE on the 50th (or Xth) bar in the future...
 
Marco vd Heijden:
Here is a related topic: https://www.mql5.com/en/forum/233876

I already have v-lines on the chart since I knew the shift , in the topic in the link they drew the v-lines using the shift

In my earlier posts I mentioned that I lose the v-lines I created when the VPS restart or during weekends or sometimes when rebooting  MT4 , so I save the dates of the v-lines in attempt to re-create them later if they were lost.

It seems that MT4 does not have the ability to create v-lines from text dates or no one has figured how its done yet 

 
Alpha Beta:

In my earlier posts I mentioned that I lose the v-lines I created when the VPS restart or during weekends or sometimes when rebooting  MT4 , so I save the dates of the v-lines in attempt to re-create them later if they were lost.

If you have saved the dates as :

datetime TimeExit_SymSymbol = (datetime) ObjectGetInteger(0, Exit_SymSymbol, OBJPROP_TIME1);

Here to recreate v-lines you don't need to split seconds digits from TimeExit_SymSymbol ..the job is done by ObjectCreate() itself ,because it doesnt take seconds in account.

You may simplify your codes by:

ObjectDelete(0,"v_line1");
ObjectCreate(0, "v_line1", OBJ_VLINE, 0, TimeExit_SymSymbol, 0);
 

Well i quickly tried a script and that certainly draws the line into the future.

//+------------------------------------------------------------------+
//|                                                        Vline.mq4 |
//|        Copyright 2019, MarcovdHeijden, MetaQuotes Software Corp. |
//|                   https://www.mql5.com/en/users/thecreator1/news |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MarcovdHeijden, MetaQuotes Software Corp."
#property link      "https://www.mql5.com/en/users/thecreator1/news"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- assemble time parameter
   datetime time=Time[0]+50*PeriodSeconds();
//--- create v line
   VLineCreate(0,"V-Line-"+TimeToString(time,TIME_DATE),0,time);
//---   
  }
//+------------------------------------------------------------------+ 
//| Create the vertical line                                         | 
//+------------------------------------------------------------------+ 
bool VLineCreate(const long            chart_ID=0,// chart's ID 
                 const string          name="VLine",      // line name 
                 const int             sub_window=0,      // subwindow index 
                 datetime              _time=0,// line time 
                 const color           clr=clrRed,        // line color 
                 const ENUM_LINE_STYLE style=STYLE_SOLID, // line style 
                 const int             width=1,           // line width 
                 const bool            back=false,        // in the background 
                 const bool            selection=false,// highlight to move 
                 const bool            ray=true,          // line's continuation down 
                 const bool            hidden=true,       // hidden in the object list 
                 const long            z_order=0)         // priority for mouse click 
  {
//--- if the line time is not set, draw it via the last bar 
   if(!_time)
      _time=TimeCurrent();
//--- reset the error value 
   ResetLastError();
//--- create a vertical line 
   if(!ObjectCreate(chart_ID,name,OBJ_VLINE,sub_window,_time,0))
     {
      Print(__FUNCTION__,
            ": failed to create a vertical line! Error code = ",GetLastError());
      return(false);
     }
//--- set line color 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set line display style 
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set line width 
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- display in the foreground (false) or background (true) 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the line by mouse 
//--- when creating a graphical object using ObjectCreate function, the object cannot be 
//--- highlighted and moved by default. Inside this method, selection parameter 
//--- is true by default making it possible to highlight and move the object 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- enable (true) or disable (false) the mode of displaying the line in the chart subwindows 
   ObjectSetInteger(chart_ID,name,OBJPROP_RAY,ray);
//--- hide (true) or display (false) graphical object name in the object list 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution 
   return(true);
  }
//+------------------------------------------------------------------+ 
//| Move the vertical line                                           | 
//+------------------------------------------------------------------+ 
bool VLineMove(const long   chart_ID=0,// chart's ID 
               const string name="VLine",// line name 
               datetime     _time=0) // line time 
  {
//--- if line time is not set, move the line to the last bar 
   if(!_time)
      _time=TimeCurrent();
//--- reset the error value 
   ResetLastError();
//--- move the vertical line 
   if(!ObjectMove(chart_ID,name,0,_time,0))
     {
      Print(__FUNCTION__,
            ": failed to move the vertical line! Error code = ",GetLastError());
      return(false);
     }
//--- successful execution 
   return(true);
  }
//+------------------------------------------------------------------+ 
//| Delete the vertical line                                         | 
//+------------------------------------------------------------------+ 
bool VLineDelete(const long   chart_ID=0,// chart's ID 
                 const string name="VLine") // line name 
  {
//--- reset the error value 
   ResetLastError();
//--- delete the vertical line 
   if(!ObjectDelete(chart_ID,name))
     {
      Print(__FUNCTION__,
            ": failed to delete the vertical line! Error code = ",GetLastError());
      return(false);
     }
//--- successful execution 
   return(true);
  }
//+------------------------------------------------------------------+ 
 
Marco vd Heijden:

Well i quickly tried a script and that certainly draws the line into the future.

Dear Marco, 

You are using the shift relevant to the current bar, which is the same method I used to create the V-Lines for my charts , however the problem is to create the V-Line without knowing the shift and without referencing the current time/bar, the problem is to create the V-Lines knowing the time/date ONLY

Since  i lose the v-lines sometimes when the VPS restarts and other times over the weekend, that is why the only option I found is to  save the time/date of the lines on the chart then try to re-create them again, saving the shift wont help much as the bars progress and also there is the weekend bars . 

according the MT4 ( https://www.mql5.com/en/docs/objects/objectcreate) the V-Line can be created using the time/date only .. I would like to see how its done since I have not seen it anywhere and I tired without any luck 

Documentation on MQL5: Object Functions / ObjectCreate
Documentation on MQL5: Object Functions / ObjectCreate
  • www.mql5.com
The function creates an object with the specified name, type, and the initial coordinates in the specified chart subwindow. During creation up to 30 coordinates can be specified. The function returns true if the command has been successfully added to the queue of the specified chart, or false otherwise. If an object has already been created, an...
 

Finally I figured how its done 

here is the code if someone ever wanted to draw V-Line using the time/date only 

         // InputDateTime= is the time you want to use to draw the VLine
       
         datetime TimeVLineFile = (datetime) ObjectGetInteger(0, InputDateTime, OBJPROP_TIME1);
         MqlDateTime str1;
         TimeToStruct(TimeVLineFile ,str1);
         int Year = str1.year;
         int Month = str1.mon;
         int Day = str1.day;
         int Hour = str1.hour;
         int Minutes = str1.min;
         int Seconds = str1.sec;
        
      
   
         string VLineDateFormat= str1.year+"."+str1.mon+"."+str1.day+" "+ str1.hour+":" + str1.min; 
         
         
         ObjectCreate(0, "L3", OBJ_VLINE, 0, StringToTime(VLineDateFormat), High[0]);
 
Alpha Beta:

Finally I figured how its done 

here is the code if someone ever wanted to draw V-Line using the time/date only 

  1. That's not how it's done. All you did was
    1. Take a datetime and convert it to the struct.
    2. Take the struct and convert it so a string (without the seconds.)
    3. Take the string and convert it back to the original datetime (without the seconds.)
    datetime TimeVLineFile = (datetime) ObjectGetInteger(0, InputDateTime, OBJPROP_TIME1);
    MqlDateTime str1;
    TimeToStruct(TimeVLineFile ,str1);
    int Year = str1.year;
    int Month = str1.mon;
    int Day = str1.day;
    int Hour = str1.hour;
    int Minutes = str1.min;
    int Seconds = str1.sec;
    
    string VLineDateFormat= str1.year+"."+str1.mon+"."+str1.day+" "+ str1.hour+":" + str1.min;   
    
    ObjectCreate(0, "L3", OBJ_VLINE, 0, StringToTime(VLineDateFormat), High[0]);

  2. If all you wanted was to remove the seconds, This is how that's done:
    datetime TimeVLineFile = (datetime) ObjectGetInteger(0, InputDateTime, OBJPROP_TIME1);
    datetime TimeVLineSansSeconds = TimeVlineFile - TimeVlineFile % 60;
    
    ObjectCreate(0, "L3", OBJ_VLINE, 0, TimeVLineSansSeconds, High[0]);
 
William Roeder:
  1. That's not how it's done. All you did was
    1. Take a datetime and convert it to the struct.
    2. Take the struct and convert it so a string (without the seconds.)
    3. Take the string and convert it back to the original datetime (without the seconds.)

  2. If all you wanted was to remove the seconds, This is how that's done:

If you looked at my previous posts you will see that I tired removing the seconds, but it didn't work, however after the conversion the code worked not sure what was wrong,

I like your version of the code its simple, elegant and it works well, thanks  

 
This is my first time utilizing graphical articles in a pointer. I would need to draw a vertical line ordinarily in the meantime "22:00", might you be able to please direct me to an answer?
Reason: