Announcement

Collapse
No announcement yet.

getCurrentBarIndex ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • getCurrentBarIndex ?

    Using a 1S interval chart, I noticed that with setComputeOnClose(), getCurrentBarIndex() returns -1 for the current bar? I thought it should be zero.

    I also noticed that without using setComputeOnClose(), so that there is intrabar data, getCurrentBarIndex() returns 0 when the bar state is BARSTATE_NEWBAR.

    Is this the way it should work? It sounds inconsistent to me. I didn't do detailed testing, but one of my formulas uses intrabar data, and the other does not, and I noticed that difference.

  • #2
    When using setComputeOnClose(), the script is always looking at the most recently completed bar, which will be at offset -1. Additionally, a bar is not considered as 'closed' until the first tick of the next bar comes in. So, if you load a daily chart after market hours (so that theoretically, today's bar is now closed) and use setComputeOnClose(), it will consider yesterday's bar as the most recent closed bar. It will not consider today's bar as 'closed' until the first tick of tomorrow's bar comes in.

    Chris

    Comment


    • #3
      So, does this mean if I want the closing price of that just closed bar, I need to call close(-1) not close()? Or, is the script assuming -1 in those functions when setComputeOnclose is set?

      TIA

      Comment


      • #4
        correct....

        with setComputeOnClose(true), the getCurrentBarIndex() returns -1. Without it, it returns 0.

        So if you are using setComputeOnClose(true) and want to get the Closing price of the current (completely formed bar), then you would use close(-1).

        If you are not using setComputeOnClose, then the current bar (that is still forming) is bar 0 (close(0) or close()) and the previous bar is -1.

        Does this help.

        B
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment

        Working...
        X