Timenum() function granularity using IQFeed

Hello -

I am attempting you use the Timenum() function to reference previous prices when scanning for signals. When using IQFeed, the output of Timenum() provides the hour and minute, but does not provide granularity up to the latest second. Example, if the time now is 133511, the output of timenum() would be 133500.

This issue goes away when I switch datafeed to IB.

Any idea how I can resolve this?

Note: I have database set to 1-second timeframe and project periodicity to 1-second as well.

_TRACE("Time " + TimeNum());
_TRACE("Time2 " + Now(4));
_TRACE("Hour " + Hour());
_TRACE("Minute " + Minute());
_TRACE("Second " + Second());

Output:
Time 133800
Time2 133827
Hour 13
Minute 38
Second 0

what is the timeframe of your database? Is it tick?

If your database has "tick" as base interval and you put your chart in the tick timeframe then your title will show microseconds

Title = StrFormat("Timestamp is = %02.0f:%02.0f:%02.0f.%03.0f%03.0f", Hour(), Minute(), Second(), MilliSec(), MicroSec() );

Thanks @empottasch

My database is set to 1-sec but the same issue occurs when set to tick

I am not using charts. This would be useful to reference previous prices when scanning using AFL code

yes Timenum() will only show seconds. You need to use functions like MilliSec() and MicroSec()

In this case it will not show the seconds. That is the issue I have. Notice the output for timenum() is 133800 instead of 133827, and the second() function returns 0

you just need to use other functions. have a look at the available Date/Time functions in the reference
https://www.amibroker.com/guide/a_catfunref.html

Thanks @empottasch , while those are viable workarounds, I would like to understand the underlying issue since the functions do work fine with IB and not IQFeed.

oh sorry I thought the issue was sub second granularity. I do not know what the issue is. Seems to work for me although I can not check it at the moment

The granularity of TimeNum() is ONE SECOND, always.

But TimeNum() shows not "current time" but BAR timestamp of ALL bars (so it returns ARRAY), not only last value.

BAR timestamp returned by TimeNum() function depend on PREFERENCES settings.

By default it shows the START time of selected intraday interval, therefore if you have selected 1-minute bars for VIEWING, it will show say 12:30:00 for entire duration of bar that begins at 12:30:00 and ends 12:30.59.999999. It is recommended to stay with default setting (mainly for alignment if you use multiple symbols)

The Now() function on the other hand returns just one time, the CURRENT time.

Therefore there is nothing "to resolve". These functions just do two different things.

Final note:

You did not send screenshots from File->Database Settings.

Please remember that the "Base time interval" setting in File->Database Settings, is intended to be set ONCE and kept unchanged. You change the interval for viewing using View menu on the fly, NOT by changing "Base time interval". If you change "Base time interval" after your database was set to different interval, you will get a mixture of data unless you do full Force Backfill. For example if you had 1-minute and changed to 1-second later, you have to do Force Backfill to get 1-second data, to actually get those 1-second bars as they are different kind of animal and go from different IQFeed server / request.

Thanks @Tomasz

By default it shows the START time of selected intraday interval, therefore if you have selected 1-minute bars for VIEWING, it will show say 12:30:00 for entire duration of bar that begins at 12:30:00 and ends 12:30.59.999999. It is recommended to stay with default setting (mainly for alignment if you use multiple symbols)

I have set it to 1-sec bars for viewing as well. I am sure of it, because when I use IB data, Timenum() output provides up to the second granularity (12:30:59). When I switch to IQFeed, without changing anything, the output is limited to the minute (12:30:00)

First: number of bars is way too low for 1-second database (3000 seconds is not even one hour worth of data).
Secondly you have apparently changed the plugin (the database has "IB" name) once database was set for Interactive Brokers.
Don't do that.

You should start NEW DATABASE via
File->New Database
and configure it properly from the start.
Databases with different vendors should be switched by changing the database (File->Open Database).