Announcement

Collapse
No announcement yet.

how to test for last bar

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

  • how to test for last bar

    Seemed reasonable to include this question in this thread - hope that is ok!

    Please tell me how to test for last bar.

    I am trying to print a debug message when the last bar is reached.
    The only bar state definitions I can find are:
    BARSTATE_NEWBAR, BARSTATE_CURRENTBAR and BARSTATE_ALLBARS
    whose values are 0, 1 and 2.

    I tried ALLBARS but that did not work.

    For example:

    The following 2 lines of code print the debug message at bar number 65.
    if(getCurrentBarCount() = 65) //WORKED OK
    {debugPrintln("*************TOTAL ERRORS=" my_error_counter));}

    The following NEVER(????) prints the debug message.
    if(getBarState() == BARSTATE_ALLBARS) //DID NOT WORK
    {debugPrintln("*************TOTAL ERRORS=" my_error_counter));}

  • #2
    Re: Please tell me how to test for last bar

    jcm21
    Use the isLastBarOnChart() function.
    With regards to BARSTATE_ALLBARS this occurs once only on the first execution of main when a formula is applied to a chart or it is reloaded or more data is loaded in the chart (by scrolling back when using a Dynamic Time Template)
    You may want to bookmark the following link to the EFS Glossary which lists all the available EFS functions in alphabetical order. Most of the names of the functions are self-explanatory (eg isLastBarOnChart) so it is relatively easy to identify what they do.
    Alex


    Originally posted by jcm21
    Seemed reasonable to include this question in this thread - hope that is ok!

    Please tell me how to test for last bar.

    I am trying to print a debug message when the last bar is reached.
    The only bar state definitions I can find are:
    BARSTATE_NEWBAR, BARSTATE_CURRENTBAR and BARSTATE_ALLBARS
    whose values are 0, 1 and 2.

    I tried ALLBARS but that did not work.

    For example:

    The following 2 lines of code print the debug message at bar number 65.
    if(getCurrentBarCount() = 65) //WORKED OK
    {debugPrintln("*************TOTAL ERRORS=" my_error_counter));}

    The following NEVER(????) prints the debug message.
    if(getBarState() == BARSTATE_ALLBARS) //DID NOT WORK
    {debugPrintln("*************TOTAL ERRORS=" my_error_counter));}

    Comment


    • #3
      jcm21.

      If you are trying to detect when all the historical bars have been processed, you can use BARSTATE_CURRENTBAR which will be given on the first tick of a real time bar.

      If you are trying to print a message when the last historical bar is being processed, you will have to use a combination of BARSTATE_NEWBAR, getCurrentBarCount(), and getOldestBarIndex()


      Steve

      Comment


      • #4
        Thanks Steve & Alex - eSignal is not quite as simple as advertised

        Thanks Steve & Alex,

        I am learning that eSignal is not quite as simple as advertised - but if it is the best then that's the one we must go with.

        Comment


        • #5
          if (getCurrentBarIndex() == 0) {

          }
          Brad Matheny
          eSignal Solution Provider since 2000

          Comment


          • #6
            Thanks Brad

            Thanks Brad, much appreciated.

            Comment

            Working...
            X