Announcement

Collapse
No announcement yet.

Why is isLastBarOnChart() true twice on a single chart?

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

  • Why is isLastBarOnChart() true twice on a single chart?

    I opened a chart of GOOG,D and it displayed a chart of 304 bars.
    I added the following script to the chart:
    "use strict;"
    var barCount = 0;
    var aGE = null;

    function main() {
    ++barCount;

    if (isLastBarOnChart() == true) {
    aGE = sym("GE");
    debugPrintln("barCount="+barCount);
    debugPrintln(JSON.stringify(['isLastBarOnChart,high(0,aGE)', high(0,aGE)]));

    }
    return;
    }
    And the following is displayed in the output window:
    ["isLastBarOnChart,high(0,aGE)",31.28]
    barCount=304
    ["isLastBarOnChart,high(0,aGE)",null]
    barCount=304

    It appears isLastBarOnChart() is true twice, i.e. the chart, or something, is loaded twice. Any thoughts on why this happens and what the multiple loads mean? I'm sure I just don't quite understand what's called and when.
    Thanks

  • #2
    I made a typo and left out setting barCount=0 inside the "if (isLastBarOnChart() == true)" block but it is there in the efs.

    Comment


    • #3
      Probably because there's 2 states involved here, BARSTATE_ALLBARS vs BARSTATE_CURRENTBAR.

      Look up 'getBarState()' in the efs function definition and you'll see what I'm referring to.

      Comment


      • #4
        Originally posted by i960 View Post
        Probably because there's 2 states involved here, BARSTATE_ALLBARS vs BARSTATE_CURRENTBAR.

        Look up 'getBarState()' in the efs function definition and you'll see what I'm referring to.
        I wouldn't think that would be a factor as ALLBARS is set once at the start of the load and CURRENTBAR is set for each bar in the series? Usually isLastBarOnChart in set once? In my case though there are 304 bars on screen main() is called 608!times. Probably has something to do with the use of sym() but not sure what.

        Comment


        • #5
          More testing shows that for a chart with 304 bars and an efs that loads a symbol that main() is called 608 times. For the first 304 the variable aGE is null then for the next 304 it is not null and I can get the values of GE.
          This indicates that the eSignal platform detects that sym() has been called and then calls main() again as many times as was done with the symbol, GOOG, displayed on the chart.
          Not sure the logic behind this but this is indeed the case. Does anyone have an idea of the reasoning behind this behavior?

          Comment


          • #6
            That does sound odd to me and doesn't really make any sense. Seems like a bug and I'd report it as the loading of another symbol inside the current efs instance shouldn't result in superfluous calls to main() twice the amount as normal.

            Comment


            • #7
              It is not a bug but an intentional [and actually required] behavior and you can find an explanation of why in this thread
              Alex


              Originally posted by i960 View Post
              That does sound odd to me and doesn't really make any sense. Seems like a bug and I'd report it as the loading of another symbol inside the current efs instance shouldn't result in superfluous calls to main() twice the amount as normal.

              Comment


              • #8
                Originally posted by ACM View Post
                It is not a bug but an intentional [and actually required] behavior and you can find an explanation of why in this thread
                Alex
                Thanks for the feedback. I figured it was behaving as designed - I just didn't know why.

                Comment

                Working...
                X