Is there a way for AFL to get the database's base time interval?

I have a chart layout that includes a 5-second chart, but it shows 1-minute data if I am using a DB with a base time interval of 1 minute. I'd like to make the chart blank instead of plotting misleading data, but Interval() only returns the user-selected interval, not the base time interval of the underlying DB.

Is there a way for AFL to get the base time interval? (If not, the workaround that I have in mind is to use a naming convention on the DB filename and check the filename for the base interval).

Using AFL I would compute the timestamp difference between 2 bars. Try something like that:

TN = 3600*Hour() + 60*Minute() + Second(); 
DTN = TN - Ref(TN,-1);
MDTN = Lowest(ValueWhen(DTN > 0, DTN));
dbi = LastValue(MDTN);
sec = Param("Expected DB Interval (sec)", 5, 5, 300, 5);
if (dbi == sec) {
	Plot(C,"",colorDefault,styleLine); // or whatever
} // else do nothing

Modify it by adding to TN days (& higher timeframes) if you deal with this kind of database.

dt = DateTime();
dt_diff = DateTimeDiff(dt,Ref(dt,-1));
if ( dt_diff[BarCount-1] == 5 AND Interval() == 5 ) {
	Title = "Is 5-seconds Interval and 5s data.";

ValueWhen is costly. Lowest() requests all bars. LastValue disables QuickAFL too.
So overall too costly just to check data interval.

i know but your formula doesn't work if some bars are missing: dt_diff could be different from the database interval. Also it doesn't work when used with volumes interval, so the only workaround i found was to check all non-zero differences.

LowestSince(is_firstvisiblebar) should be better than Lowest.

dt = DateTime();
dt_diff = DateTimeDiff(dt,Ref(dt,-1));
dt_diff = LowestSince(NOT Status("barvisible"), dt_diff);
if ( dt_diff[BarCount-1] == 5 AND Interval() == 5 ) {
	Title = "Is 5-seconds Interval and 5s data.";

He does not need volume interval but 5 sec interval.

1 Like

Well, not that much. You should not see difference between ValueWhen and other array functions. As to original poster question, I will simply add that to Status() function.
In next version you will simply write:


Out of curiosity after @fxshrat answer I benchmarked both formulas (repeating them 100 times in a loop) and indeed I couldn't find a significant difference, maybe a fraction of ms.
@Tomasz Could you take into account/distinguish tick databases too ? Thanks a lot.

He was talking about ValueWhen.

Lowest() does request all bars. So there IS a difference if there is much data (bars).
Eg. I checked on >100k bars and it is around 100 times slower then.

Wow, you guys are THE BEST!!! :trophy:

Not only do I have a solution for now, but TJ is making a change to AB for me!

And I learned a few things about what affects execution speed, too. Thanks!

This is why I use AB and participate on this forum, it's because of the fantastic support like this.


This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.