Announcement

Collapse
No announcement yet.

BARSTATE_NEWBAR Clarification Request

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

  • BARSTATE_NEWBAR Clarification Request

    Hi,

    When using a minute based bar chart for stocks, the
    getBarState() flag is set to BARSTATE_NEWBAR when a new bar comes in. My question is:

    Does the barstate continue to get set to BARSTATE_NEWBAR for every tick in the bar? That seems to be happening to me and I only want the code to execute on the first tick of a bar. If yes can one code around this? Thanks for any help you may be able to provide.
    Regards
    Jane

  • #2
    Re: BARSTATE_NEWBAR Clarification Request

    Jane
    BARSTATE_NEWBAR occurs only on the first tick of a new bar
    Alex


    Originally posted by jg
    Hi,

    When using a minute based bar chart for stocks, the
    getBarState() flag is set to BARSTATE_NEWBAR when a new bar comes in. My question is:

    Does the barstate continue to get set to BARSTATE_NEWBAR for every tick in the bar? That seems to be happening to me and I only want the code to execute on the first tick of a bar. If yes can one code around this? Thanks for any help you may be able to provide.
    Regards
    Jane

    Comment


    • #3
      Re: Re: BARSTATE_NEWBAR Clarification Request

      Hi Alex,

      Thank you very much for your clarification. Unfortunately I am more confused now. Your information leads me to understand that the BARSTATE_NEWBAR is set only on the first tick of a bar. So on a 5 min bar chart, the code should only get executed once per bar. This is not what I am observing. I have the code snippet

      if(getBarState() == BARSTATE_NEWBAR) {
      ....
      }

      and from the performance monitor window I can see that the code above gets executed on every trade in the bar. I set up the code because I initially understood the barstate to be what you stated but that is not the behaviour I am seeing. I am very puzzled.

      Regards,
      Jane

      Originally posted by Alexis C. Montenegro
      Jane
      BARSTATE_NEWBAR occurs only on the first tick of a new bar
      Alex

      Comment


      • #4
        Re: Re: Re: BARSTATE_NEWBAR Clarification Request

        Jane
        The efs will be executed on every tick but the code enclosed in the BARSTATE_NEWBAR conditional statement will be executed only on the first tick of every bar. You can easily verify this by running a counter inside that condition
        Alex


        Originally posted by jg
        Hi Alex,

        Thank you very much for your clarification. Unfortunately I am more confused now. Your information leads me to understand that the BARSTATE_NEWBAR is set only on the first tick of a bar. So on a 5 min bar chart, the code should only get executed once per bar. This is not what I am observing. I have the code snippet

        if(getBarState() == BARSTATE_NEWBAR) {
        ....
        }

        and from the performance monitor window I can see that the code above gets executed on every trade in the bar. I set up the code because I initially understood the barstate to be what you stated but that is not the behaviour I am seeing. I am very puzzled.

        Regards,
        Jane

        Comment


        • #5
          Re: Re: Re: Re: BARSTATE_NEWBAR Clarification Request

          Hi Alex,

          Thank you very much for your reply. As usual you are 100% correct. I in fact did the counter approach you suggested and it confirmed what you say. I was just confused by all the calls being made to the portion of code that computes my series values - as seen in the performance monitor window. Once again, very many thanks for your invaluable help.
          Regards,
          Jane


          Originally posted by Alexis C. Montenegro
          Jane
          The efs will be executed on every tick but the code enclosed in the BARSTATE_NEWBAR conditional statement will be executed only on the first tick of every bar. You can easily verify this by running a counter inside that condition
          Alex

          Comment

          Working...
          X