BarDate() vs BarIndex()

For some situations (e.g. timecounts) it may be better to use the BarIndex() function instead of BarDate().

The key difference is that BarDate uses calendar days and BarIndex will count the number of bars available i.e. trading days on a daily chart.

BarDate counts the number of calendar days since December 31st 1899, so all charts will have the same BarDate value for the current bar (44,574 for January 13th 2022) whereas the BarIndex will count the number of bars available for that particular chart (i.e. 1,148 for APT:ASX vs 7,673 for CBA:ASX).

If you put the functions in a Show View below the chart you will see the values (note switching to a weekly timeframe will change the BarIndex values as there will be fewer bars on the screen, whereas BarDate will change to the value of the Friday of the current week):

Capture

So when looking to count trading days back from the current bar use the following in a Show Bar to highlight the bar 49 trading days ago:

V1 = BARINDEX(); 
V1 == LAST(V1)-49

For Calendar Days use BarDate:

V1 = BARDATE(); 
V1 == LAST(V1)-49

In this example the red Show Bar arrow highlights 49 trading days prior to the current bar, and the green shows 49 calendar days. These will move automatically as new data is added and the BarIndex and BarDate values increase:

Capture