Announcement

Collapse
No announcement yet.

BARSTATE_CURRENTBAR vs CurrentBarIndex

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

  • BARSTATE_CURRENTBAR vs CurrentBarIndex

    What are the differences between the following two statements? When does one give different information than the other?

    PHP Code:
    if(getCurrentBarIndex() == 0)

    if(
    getBarState() == BARSTATE_CURRENTBAR

  • #2
    Gavishti,

    I was under the impression, but have never tested to verify that
    if(getBarState() == BARSTATE_CURRENTBAR) would always be true when a new tick has come in regardless of which bar you are on.

    if(getCurrentBarIndex() == 0) on the other hand will only be true when you are at the most recent bar.

    This should be easy enough to test...

    Garth
    Garth

    Comment


    • #3
      Thanks Garth.

      What I am attempting to do is understand how to best utilize these two states/functions.

      As I understand it, main() is executed on every tick. If that is correct what is the purpose of BARSTATE_CURRENTBAR? Can I rely on it to return true only after all of the historical data has been loaded?

      Along related lines, can anyone explain why if(getBarState == BARSTATE_ALLBARS) is sometimes executed two or three times when the efs is loaded? This seems contrary to the state I thought it was conveying. Shouldn't the efs complete the loading of data before returning?

      Comment


      • #4
        Ahh, I get it. It is my understanding that CURRENT bar will only be true with live data.

        As I test, I just wrote the attached, and it would seem that my understanding is correct.

        I have never seen ALLBARS execute more than once per load, so I can't comment on that one.

        As for the difference between CURRENTBAR and a bar index of 0...an index of 0 can be true on a NEWBAR, while CURRENTBAR, by definition, will not be true.

        It seems to me CURRENTBAR would also allow you to specify main as a callback from a mouse function as you could then determine if it was a tick that called main or a mouse click (** NOTE: I am not recommending this **).

        Garth
        Attached Files
        Garth

        Comment


        • #5
          Gavishti
          With regards to the BARSTATE_ALLBARS executing more than once I think that can happen with Dynamic Time Templates when the first - and sometimes subsequent - data downloads do not fill up the chart thereby initiating new requests for data.
          Alex

          Comment


          • #6
            Which would explain why I never see it, I never use dynamic charts.

            If Alex is correct, and if I understand him correctly, this would be easy to test. One would assume that scrolling back past the amount of data drawn would also generate an ALLBARS, as it would be requesting more data.

            Garth
            Garth

            Comment


            • #7
              Garth
              Yes that is exactly what I meant.
              Another way to see it without even scrolling would be to load a high count volume-bar chart for a relatively low volume security. With a Dynamic Template it should first complete the download for one day and if that does not fill the chart it immediately requests a second day, etc.
              Alex

              Comment


              • #8
                Thanks. This helps.

                The Dynamic makes sense on the ALLBARS. Not sure if that was the case when I noticed the multiple executions, but certainly could have been. I know that others have seen this as well.

                Regarding CURRENTBAR I found that it also works in playback. And two conditions must be met. First, there must be a Trade. Bid/Ask will not trigger it. Second, there must be a price change.

                That a mouse click forces execution of main() is nice to know. My prior information was that only the data stream could cause execution of main(). This is much better.

                Comment

                Working...
                X