OBJ_VLINE - page 2

To add comments, please log in or register
Marco vd Heijden
Moderator
11510
Marco vd Heijden  
Also you do not have to recreate the object on every tick this will flood the error log with a 4200 Object already exists, so in stead create the object in the on init function once and then you can move it to the desired date later on.
paul selvan
627
paul selvan  
Marco vd Heijden:
Also you do not have to recreate the object on every tick this will flood the error log with a 4200 Object already exists, so in stead create the object in the on init function once and then you can move it to the desired date later on.

to avoid that issue :

ObjectDelete(0,"v_line");
ObjectCreate(0,"v_line",OBJ_VLINE,0,D'2019.06.04 16:00',0);
Marco vd Heijden
Moderator
11510
Marco vd Heijden  

Or additionally you can check up front to see if the object already exists by:

ObjectFind(...
Alpha Beta
91
Alpha Beta  

Marco, Paul 

Thanks a lot for the reply and the help 

However , the issue I am facing right now is to convert the information (date) I retrieve from the file and use it to draw the lines 

In the code the file is saved as  # Lines in the MT4 files section and the date saved is for example 2019.05.18 05:30:00  , first step I remove the 

last 3 digits from the date and convert it to 2019.05.18 05:30   .. now the next step is what I am failing to achieve to make the time in the D' format 

I tried this following 

 ObjectCreate(0,"v_line",OBJ_VLINE,0,"D'"+2019.05.18 05:30+"'",0);

but that did not work , so I convert the string to time 

ObjectCreate(0,"v_line",OBJ_VLINE,0,StringToTime("D'"+2019.05.18 05:30+"'"),0);

In both cases the line is created at 1970.01.01 00:00 so the issue is to convert the date from the file into something meaningful MT4 can use to create the v-line 

I am attaching the code , maybe you can spot my mistake .. in the code I created two lines but none of the lines are created on the date i retrieve from the file 

Files:
paul selvan
627
paul selvan  

you are doing that wrong by writing the date between quotes 

as it is :

D'2019.05.18 05:30'


ObjectCreate(0,"v_line",OBJ_VLINE,0,D'2019.05.18 05:30',0);
William Roeder
18878
William Roeder  
StringToTime("2019.05.18 05:30") == D'2019.05.18 05:30'

Both are datetimes. Just as

StringToDouble("1.234") == 1.234
are both doubles.
Alpha Beta
91
Alpha Beta  
paul selvan:

you are doing that wrong by writing the date between quotes 

as it is :

D'2019.05.18 05:30'


I am doing so because I am converting the text into a datetime format as William Roeder illustrated above .. I am not sure where is my mistake since i save the date correctly and convert it to D' format but still unable to create the line , though if I copied the date from the file and manually created a line it goes into the correct date 

Marco vd Heijden
Moderator
11510
Marco vd Heijden  
I think you will have more luck saving and reading time as long integer values like seconds since epoch in stead of these string to datetime conversions.
Alpha Beta
91
Alpha Beta  
Marco vd Heijden:
I think you will have more luck saving and reading time as long integer values like seconds since epoch in stead of these string to datetime conversions.

The date is saved including seconds,  for example this is the time pulled from the file 2019.05.19 15:00:00

However during my tests , I found out that  if I used the date with seconds it will create the line in 1970.01.01 ,thats the reason why I remove the seconds , but still unable to create the file on the correct location of the date 

Marco vd Heijden
Moderator
11510
Marco vd Heijden  

In that case i think you can also look at the time structure: 

struct MqlDateTime 
  { 
   int year;           // Year 
   int mon;            // Month 
   int day;            // Day 
   int hour;           // Hour 
   int min;            // Minutes 
   int sec;            // Seconds 
   int day_of_week;    // Day of week (0-Sunday, 1-Monday, ... ,6-Saturday) 
   int day_of_year;    // Day number of the year (January 1st is assigned the number value of zero) 
  };

You can use 

TimeToStruct()

Function as follows:

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

MqlDateTime str1;

TimeToStruct(TimeExit_SymSymbol,str1); 

Then you can extract all desired values from this.

int Year = str1.year;
int Month = str1.mon;
int Day = str1.day;
int Hour = str1.hour;
int Minutes = str1.min;
int Seconds = str1.sec;
These are integer values so no strings to mess with.
To add comments, please log in or register