position objects using time values

To add comments, please log in or register
jshumaker35
10
jshumaker35  

According to the documentation on the ObjectCreate function (https://docs.mql4.com/objects/objectcreate), I should be able to pass a datetime value for the anchor point.  I have used multiple formats for the datetime value.  Regardless of the format of the datetime value, the object is always placed at 1970.01.01 00:00

ObjectCreate - Object Functions - MQL4 Reference
ObjectCreate - Object Functions - MQL4 Reference
  • docs.mql4.com
The function creates an object with the specified name, type, and the initial coordinates in the specified chart subwindow of the specified chart. There are two variants of the function: [in]  Number of the chart subwindow. 0 means the main chart window. The specified subwindow must exist (window index must be greater or equal to 0 and less...
Fernando Carreiro
4145
Fernando Carreiro  
jshumaker35: According to the documentation on the ObjectCreate function (https://docs.mql4.com/objects/objectcreate), I should be able to pass a datetime value for the anchor point.  I have used multiple formats for the datetime value.  Regardless of the format of the datetime value, the object is always placed at 1970.01.01 00:00
Show your code sample so we can analyse what you are doing wrong!
jshumaker35
10
jshumaker35  
Fernando Carreiro:
Show your code sample so we can analyse what you are doing wrong!
ObjectCreate(0,"arrow",OBJ_ARROW,0,2018-09-20,1.3297);

object list

I used the line of code above with a hard coded datetime value.  The screen shot shows the time parameter of the object in the chart

Fernando Carreiro
4145
Fernando Carreiro  
jshumaker35: I used the line of code above with a hard coded datetime value.  The screen shot shows the time parameter of the object in the chart

That is not a proper date format!

ObjectCreate(0,"arrow",OBJ_ARROW,0,2018-09-20,1.3297);

This is a proper date format:

ObjectCreate(0,"arrow",OBJ_ARROW,0,D'2018.09.20',1.3297);

Read the documentation on the datetime data type:

Datetime Type

The datetime type is intended for storing the date and time as the number of seconds elapsed since January 01, 1970. This type occupies 8 bytes of memory.

Constants of the date and time can be represented as a literal string, which consists of 6 parts showing the numerical value of the year, month, day (or day, month, year), hours, minutes and seconds. The constant is enclosed in single quotation marks and starts with the D character.

Values range from 1 January, 1970 to 31 December, 3000. Either date (year , month, day) or time (hours, minutes, seconds), or all together can be omitted.

With literal date specification, it is desirable that you specify year, month and day. Otherwise the compiler returns a warning about an incomplete entry.  

Examples:

datetime NY=D'2015.01.01 00:00';     // Time of beginning of year 2015
datetime d1=D'1980.07.19 12:30:27';  // Year Month Day Hours Minutes Seconds
datetime d2=D'19.07.1980 12:30:27';  // Equal to D'1980.07.19 12:30:27';
datetime d3=D'19.07.1980 12';        // Equal to D'1980.07.19 12:00:00'
datetime d4=D'01.01.2004';           // Equal to D'01.01.2004 00:00:00'
datetime compilation_date=__DATE__;             // Compilation date
datetime compilation_date_time=__DATETIME__;    // Compilation date and time
datetime compilation_time=__DATETIME__-__DATE__;// Compilation time
//--- Examples of declarations after which compiler warnings will be returned
datetime warning1=D'12:30:27';       // Equal to D'[date of compilation] 12:30:27'
datetime warning2=D'';               // Equal to __DATETIME__

The string representation of datetime type depends on compilation mode:

  datetime date=D'2014.03.05 15:46:58';
  string str="mydate="+date;
//--- str="mydate=1394034418" - without #property strict
//--- str="mydate=2014.03.05 15:46:58" - with #property strict


Datetime Type - Integer Types - Data Types - Language Basics - MQL4 Reference
Datetime Type - Integer Types - Data Types - Language Basics - MQL4 Reference
  • docs.mql4.com
Constants of the date and time can be represented as a literal string, which consists of 6 parts showing the numerical value of the year, month, day (or day, month, year), hours, minutes and seconds. The constant is enclosed in single quotation marks and starts with the D character. Values range from 1 January, 1970 to 31...
To add comments, please log in or register