BarDate() vs BarIndex()

Optuma Forums Optuma Scripting BarDate() vs BarIndex()

Tagged: ,

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #67253
    Darren
    • Topics: 69
    • Replies: 742
    • Posts: 811

    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:

    For Calendar Days use BarDate:

    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

    1 user thanked author for this post.
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Pin It on Pinterest