How do I correctly obtain date / time of a given bar that is comparable


After browsing through the ADK documentaion, I have found more than one way to obtain dates and they are enumerated here. Ideally I want one function that returns me date value that is comparable wtih one another and code is not cumbersome to use / debug. These are following approaches tried
thus far.

Approach one: Use gSite.GetDateTimeArray

unsigned long long *dateArray = gSite.GetDateTimeArray();

The values that I get are typically like 19 digit numbers but I am unable to find any documentation on how to use them. They seem comparable, but are they?

9090133071771992064 supposedly represents 13:14 on 19 June 2018 but how to translate this back and forth.

This had seemed to be the most promising approach but stumped for my inability to find proper documentation

Approach two: Use gSite.CallFunction and retrieve values of built in AFL function, DateTime

Amivar dateTimeArray = gSite.CallFunction("DateTime", 0, NULL);

Again values returned are typically 19 digit numbers and I did find article about how amibroker fits datetime in 4 bytes whereas Microsoft took 8 bytes.

Put this approach to rest after the DateTime documentation clearly says that this values are not directly comparable and one is meant to use DateTimeDiff function

Approach three: Use gSite.CallFunction and retrieve values of built in AFL function, DateNum and TimeNum.

Discounting the absence of century in datenum, this is by far the easiest approach

Approach four: Use gSite.CallFunction and retrieve values of built in AFL function, Year, Month, Day, Hour, Minute, Second ... etc....

This approach works OK but it is cumbersome (and definitely slow) to compare two sets of date.
One another anomaly that I noticed is that array holding Seconds often contain values other than zero. Chart time frame (and database resolution) both are 1 minute. Could this be reason for Seconds array to have inappropriate values?

Use Approach 1. See the ADK Plugin.h header file. There you will find description/definition of 64-bit date time structure (AmiDate/PackedDate). Once you do this, you will easily find fields for seconds, minutes, hours, etc.


Hello Tomasz

Thanks. That worked like a charm. I looked all over the google and help document but did not scroll into the .h file that was sitting right before me. My mistake!

Setting the date in AmiDate variable unravels the encoding.

Few more sub-questions

Q1) Will time data present returrned by GetDateTimearray() correspond exactly to a bar? i.e. if user has selected interval as hourly, I'd expect minute and seconds to remain zero.

Q2) To correctly compare two AmiDates to obtain "greater than" "less " resulttant states, I would have to compare all of the elements of PackDate in inverted manner i.e. year, month, day, hour, minute, second.... ?

Q3) If I wanted to store AmiDate into a Static variable from the Plugin, how would I do it?

1 Like
  1. Yes

  2. As you might noticed 64-bit datetime can be treated as struct or as just 64-bit integer. It is defined so, when you treat it as integer you can do normal comparisions >, <. = and they all work correctly so there is no need to compare fields, just compare one 64-bit integer to another.

  3. gSite.CallFunction("StaticVarSet"....)


AmiDate is 8 byte structure and staticvarset accepts AmiVar which is combination of 4 bytes for type and 4 bytes for value or pointer to float or pointer to string.

That is true. You can't use AmiDate directly for that purpose. You need to use function like _DT() or StrToDateTime to generate 32-bit float representing value that you could pass as argument to CallFunction.