Announcement

Collapse
No announcement yet.

getBarStateSymbol() query

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

  • getBarStateSymbol() query

    I've been using getBarStateInterval(), and noted the "use once" requirement. Seems fine when using time periods that are a multiple of the "chart" period.

    I'm concerned that I don't understand getBarStateSymbol() though.

    1) My main() will get called for every tick in my symbol context (computeOnClose() not set).

    2) But before I get the first tick in a new bar in my symbol context, a different symbol could have had several ticks, even if the intervals are the same. What will happen when I call getBarStateSymbol() in that situation? Will I miss the BARSTATE_NEWBAR (defined as "the first tick of a new bar has arrived") and thus miss the close of the previous bar?

    Put another way, "does getBarStateSymbol() always return BARSTATE_NEWBAR when called after a bar closes, even though it may be called after the bar has seen more than one tick?"

    I also wonder what would happen if the longer intervals were not multiples of the chart interval (for the same symbol), would I miss the longer bars there too (using getBarStateInterval())?

    Perhaps the way the indicator works wrt time might affect the answer....
    Although my indicator does some per-tick computation (for one or more symbols and intervals) and displays a value, I'm not really interested in that value until I get completed bars (in all symbols and time periods, further computation occurs then), in between the closes just the high, low and "price within the last few 10s of seconds" will do fine. So really what I would like is a time-based call to main()?

    Thanks

  • #2
    Re: getBarStateSymbol() query

    Hello Dave,

    Originally posted by Dave180
    I've been using getBarStateInterval(), and noted the "use once" requirement. Seems fine when using time periods that are a multiple of the "chart" period.

    I'm concerned that I don't understand getBarStateSymbol() though.

    1) My main() will get called for every tick in my symbol context (computeOnClose() not set).
    Correct. It also gets called for every tick of the specified symbol used by getBarStateSymbol() or any series that is set to an external symbol.

    2) But before I get the first tick in a new bar in my symbol context, a different symbol could have had several ticks, even if the intervals are the same. What will happen when I call getBarStateSymbol() in that situation? Will I miss the BARSTATE_NEWBAR (defined as "the first tick of a new bar has arrived") and thus miss the close of the previous bar?
    getBarStateSymbol() will return the state for the specified symbol. You will get a NEWBAR return for the external symbol on it's first tick of the new interval it is based on. That tick could be after the newbar state, or first tick, for the chart symbol where the formula is running. You won't miss the newbar state of the external interval as long as it as at least one tick during the interval. If no trades occur for the external symbol for the entire duration of one interval, then no newbar state will occur for the external symbol on that one interval. Advanced charts do not display zero volume bars. Therefore, if you are comparing one symbol that is infrequently traded to a symbol with a lot of activity on a short term interval, you may not always get the newbar state for both symbols on each interval (or bar).

    Put another way, "does getBarStateSymbol() always return BARSTATE_NEWBAR when called after a bar closes, even though it may be called after the bar has seen more than one tick?"
    It doesn't get called when a bar closes based on time. The EFS will only execute when a trade occurs. The first trade that occurs for a new interval's window of time will generate a newbar return from the getBarState(), getBarStateInterval() or getBarStateInterval() functions. For each trade that occurs after the opening trade for the interval a BARSTATE_CURRENTBAR state is returned by those functions.

    I also wonder what would happen if the longer intervals were not multiples of the chart interval (for the same symbol), would I miss the longer bars there too (using getBarStateInterval())?
    Yes, because if the longer interval spans across multiple bars for the lower interval, you can not get a newbar state for the longer interval on each of the lower interval bars.

    Perhaps the way the indicator works wrt time might affect the answer....
    Although my indicator does some per-tick computation (for one or more symbols and intervals) and displays a value, I'm not really interested in that value until I get completed bars (in all symbols and time periods, further computation occurs then), in between the closes just the high, low and "price within the last few 10s of seconds" will do fine. So really what I would like is a time-based call to main()?

    Thanks
    We do not have control over when main() can be executed other than using the setComputeOnClose() option. Forcing main() to execute at specific times is not currently possible.
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Ah, the light dawns
      It also gets called for every tick of the specified symbol used by getBarStateSymbol() or any series that is set to an external symbol
      I don't think it's clearly stated that main() gets called for the ticks in the external symbols. Knowing that makes everything clear. I don't think the docs make this obvious (hence my confusion), could it be added? Anyway, I now understand I won't miss ticks in the external symbols.

      Two queries then:

      You actually say
      the specified symbol used by getBarStateSymbol() or
      Do you mean, " if getBarStateSymbol() is called for, say, "IBM", main will be called for any IBM ticks, even if no series are based on IBM." But presumably this won't happen until after the first call to getBarStateSymbol()?

      2) Commonly we see
      //perform some initialization actions when script is first loading
      if (getBarState() == BARSTATE_ALLBARS) {

      Is this guaranteed to occur before any tick from a different symbol? [On reflection, I assume it is because no other symbol-based series have been defined.]

      I'm afraid some more queries have arisen, see other posts.


      Thanks

      Dave
      Last edited by Dave180; 06-13-2007, 03:48 PM.

      Comment


      • #4
        Hello Dave,

        Originally posted by Dave180


        Do you mean, " if getBarStateSymbol() is called for, say, "IBM", main will be called for any IBM ticks, even if no series are based on IBM." But presumably this won't happen until after the first call to getBarStateSymbol()?
        Yes, that is correct.


        2) Commonly we see


        Is this guaranteed to occur before any tick from a different symbol? [On reflection, I assume it is because no other symbol-based series have been defined.]
        Yes it should. You could alternatively use a global initialization flag.

        PHP Code:
        var bInit false;

        function 
        main() {
            if (
        bInit == false) {
                ... 
        initialization code
                bInit 
        true;
            }

            ....

        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment


        • #5
          thanks, Dave

          Comment


          • #6
            You're most welcome.
            Jason K.
            Project Manager
            eSignal - an Interactive Data company

            EFS KnowledgeBase
            JavaScript for EFS Video Series
            EFS Beginner Tutorial Series
            EFS Glossary
            Custom EFS Development Policy

            New User Orientation

            Comment

            Working...
            X