Announcement

Collapse
No announcement yet.

Question regarding BARSTATE_ALLBARS

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

  • Question regarding BARSTATE_ALLBARS

    My question seems to be along the same lines of this trend, so I'm posting it here.

    I have a EFS study that has setComputeOnClose() in the preMain(). In this same study, I want it to wait till all bars have loaded before running. In this situation I use this statement:

    if (getCurrentBarIndex() != -1) {return;}

    First question, is this the best way to do this or is there something else?

    Second question: on a TICK chart, the above statement seems to work fine (on the initial loading of the chart). However, if I drag the chart over to view past bars that causes the chart to load more historical data, my EFS keeps running during this loading of data. I do not want that. I want my EFS to wait while this additional data is loading. How can I do that?

    I tried the following, but it didn't seem to work:
    if (getBarState() == BARSTATE_ALLBARS) return;


    Any help is greatly appreciated!
    Thanks!
    Daniel
    Last edited by neoikon; 09-17-2009, 11:24 AM.
    eSignal File Share: http://share.esignal.com/groupcontents.jsp?groupid=1130

  • #2
    You seem to be accomplishing this the wrong way...

    First, you would want to use..

    if (getCurrentBarIndex() == 0) {
    }

    as a test to determine if you are on the LAST BAR ON THE CHART (current realtime bar).

    or

    if (getBarState() == BARSTATE_ALLBARS) {
    }

    Another way to prevent your EFS from running on historical bars is...

    if (getCurrentBarIndex() != 0) {
    }

    or

    if (getBarState() != BARSTATE_ALLBARS) {
    }
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Brad
      FWIW bar index 0 is not processed when using setComputeOnClose() You can verify this by running the following script and you will see that the debug line is not executed. If you then replace 0 with -1 it will execute the debug line
      PHP Code:
      function preMain(){
          
      setComputeOnClose()
      }

      function 
      main(){
          if(
      getCurrentBarIndex()==0){
              
      debugPrintln("this is bar index 0");
          }

      Also BARSTATE_ALLBARS returns true on the first bar in the chart and not on the most recent. You can verify this by running the following script and you will see that the bar index returned to the Formula Output Window is the oldest on the chart.
      Alex

      PHP Code:
      function main(){
          if(
      getBarState()==BARSTATE_ALLBARS){
              
      debugPrintln("this is bar index "+getCurrentBarIndex());
          }


      Originally posted by Doji3333
      You seem to be accomplishing this the wrong way...

      First, you would want to use..

      if (getCurrentBarIndex() == 0) {
      }

      as a test to determine if you are on the LAST BAR ON THE CHART (current realtime bar).

      or

      if (getBarState() == BARSTATE_ALLBARS) {
      }

      Another way to prevent your EFS from running on historical bars is...

      if (getCurrentBarIndex() != 0) {
      }

      or

      if (getBarState() != BARSTATE_ALLBARS) {
      }

      Comment


      • #4
        Thanks Alex. I did not realize the setComputeOnClose() function altered the addressing of the bars on the chart.

        I can't understand why, but I'm not going to question the reasons.

        Personally, I never use setComputeOnClose(). I always develop my scripts to run in RT and simply reference the -1 bars when a new bar forms to accomplish the same thing.

        Again, I appreciate the heads up.
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment


        • #5
          Brad
          It does not alter the addressing of the bars on the chart. It just does not process bar index 0 [ie the most current one] as that bar is completed only when a new one is formed.
          Alex


          Originally posted by Doji3333
          Thanks Alex. I did not realize the setComputeOnClose() function altered the addressing of the bars on the chart.

          I can't understand why, but I'm not going to question the reasons.

          Personally, I never use setComputeOnClose(). I always develop my scripts to run in RT and simply reference the -1 bars when a new bar forms to accomplish the same thing.

          Again, I appreciate the heads up.

          Comment


          • #6
            Originally posted by neoikon

            Second question: on a TICK chart, the above statement seems to work fine (on the initial loading of the chart). However, if I drag the chart over to view past bars that causes the chart to load more historical data, my EFS keeps running during this loading of data. I do not want that. I want my EFS to wait while this additional data is loading. How can I do that?

            I tried the following, but it didn't seem to work:
            if (getBarState() == BARSTATE_ALLBARS) return;
            Had the same question as the OP. It wasn't explicitly answered so I'll post what I came up with for anyone else:

            PHP Code:
            /*
            *   Simple eSignal EFS test program to only do processing on last full/complete bar.
            *   
            *   Ignores loading of past historical bars, including when more older bars are loaded 
            *   after scrolling back to see past price data.
            *   
            *   Once all bars are received, computes a simple average of all price bars.
            *   
            */

            // global variables...
            var bHistoricalBarsLoading false;


            function 
            preMain(){
                
            // we want complete bars only:
                
            setComputeOnClose();    // don't send main() BARSTATE_CURRENTBAR or bar index 0
            }


            function 
            main(){
                
            // optimization...
                
            var barState getBarState();
                var 
            currentBarIndex getCurrentBarIndex();
                var 
            numBars getNumBars();

                
            //
                // Code to ignore loading of historical (past) bars...
                //
                
            if (barState == BARSTATE_ALLBARS) {
                    
            bHistoricalBarsLoading true;
                    
            debugPrintln ("STARTing ignoring historal bar loading...");
                    
                    
            debugPrintln ("getBarState(): BARSTATE_ALLBARS");
                    
            debugPrintln ("getCurrentBarIndex(): " currentBarIndex);
                    
            debugPrintln ("getNumBars(): " numBars);
                    
            debugPrintln ("----");
                }

                if (
            currentBarIndex == -1) {
                    if (
            bHistoricalBarsLoading) {
                        
            bHistoricalBarsLoading false;
                        
            debugPrintln ("ENDing ignoring historal bar loading...");
                    }
                }

                if (
            bHistoricalBarsLoading) return;


                
            //
                // We're only processing the last full bar...
                //

                
            if (barState == BARSTATE_CURRENTBAR) {
                    
            // since setComputeOnClose() was called, we shouldn't ever get here...
                    
            debugPrintln ("getBarState(): BARSTATE_CURRENTBAR");
                }

                if(
            currentBarIndex == 0){
                    
            // since setComputeOnClose() was called, we shouldn't ever get here...
                    
            debugPrintln ("getCurrentBarIndex(): " currentBarIndex);
                    
            debugPrintln("----");
                }

                if(
            currentBarIndex == -1){
                    
            debugPrintln ("getCurrentBarIndex(): " currentBarIndex);
                    
            debugPrintln ("getNumBars(): " numBars);

                    
            // compute a simple average of all bars.
                    // (this code isn't very efficient in RT, but this is just test code...)
                    
            var tot 0;
                    var 
            numBarsWeAreUsing numBars currentBarIndex;  // don't include current, incomplete bar (bar index 0)
                    
            for (var 0numBarsWeAreUsingb++) {
                        
            tot tot close (-b);
                    }
                    
            debugPrintln ("Average = " + (tot numBarsWeAreUsing) );

                    
            debugPrintln("----");
                }


            Comment


            • #7
              While the code I posted below works fine for 1 minute intervals, etc., it doesn't seem to quite work with TICK charts.

              Basically what seems to happen is the code receives several "chunks" of tick data when loading more data. However, only after the last "chunk" is received is BARSTATE_ALLBARS set.

              I'll repost once/if I understand it better and get the code working with TICK charts....
              Last edited by shortandlong; 10-28-2009, 11:20 AM.

              Comment


              • #8
                What I've found so far...

                When comparing a test for last bar (with setComputeOnClose() called in preMain) using:
                1. getCurrentBarIndex() == -1
                2. eSignal's isLastBarOfChart()
                3. my own custom isLastBar()

                I found the following:
                • All 3 methods agree with 1 minute bars. (Haven't tested 5, 10, etc. minute bars yet.)
                • For time periods D[aily], W[eekly], and M[onthly] isLastBarOfChart() is NEVER true! The other 2 methods are correct and agree.
                • For TICK charts during initial loading, a manual refresh, or when dragging the chart to see more older data, all 3 methods report last bar MORE THAN ONCE! I've seen last bar reported up to 1 to 2 dozen times during a refresh or initial load! Ironically behavior seems worse (or only occurs) during market hours. Using my own custom isLastBar() I've managing to eliminate over half of these, but the multiple calls to main() with BARSTATE_ALLBARS is confusing my EFS code's ability to reduce them.

                I've always been perplexed by eSignal's limited ability to handle tick charts. Now I understand why. On TICK charts with over 300 bars or so, during initial load, refreshes, or when dragging to see more past bars; any EFS main() is, at times, called for every bar in the chart OVER AND OVER AGAIN!, not ONCE like it should be, but MULTIPLE TIMES!

                In my experience, whether a market data system can handle RT updates from a performance perspective is determined by whether one can bring up the system in the middle of a heavy market day (after a power failure, crash, etc.). This problem with TICK chart EFS performance seems to severely cap what indicators can be developed for eSignal due to an unnecessary startup / page load CPU demand.

                Comment


                • #9
                  Unfortunately, the multiple BARSTATE_ALLBARS issue also occurs with 1 minute and D[aily] charts, it just doesn't seem as bad...
                  Last edited by shortandlong; 10-30-2009, 03:51 PM.

                  Comment


                  • #10
                    Originally posted by shortandlong

                    Using my own custom isLastBar() I've managing to eliminate over half of these, but the multiple calls to main() with BARSTATE_ALLBARS is confusing my EFS code's ability to reduce them.
                    I am experiencing all of the behaviors you are listing.

                    I primarily use tick charts and have developed some pretty CPU intensive scripts, so when the chart falsely claims getBarState() == BARSTATE_ALLBARS every 300 bars, it takes quite a long time to load the past 2000-3000 bars.

                    Can you share what you've discovered in your custom isLastBar() script?

                    Thanks!
                    Daniel
                    eSignal File Share: http://share.esignal.com/groupcontents.jsp?groupid=1130

                    Comment


                    • #11
                      Originally posted by neoikon
                      I primarily use tick charts and have developed some pretty CPU intensive scripts, so when the chart falsely claims getBarState() == BARSTATE_ALLBARS every 300 bars, it takes quite a long time to load the past 2000-3000 bars.

                      So, after some research, I found a decent solution that gives me better performance. (and also allows me to not manually load 2000+ bars by dragging the chart)

                      I created a time template that is no longer "dynamic", but instead is a fixed size. In my case, "3 days". This way it will load 3 days worth of bars, right off the bat, and getBarState() will only equal BARSTATE_ALLBARS one time, when all bars are loaded.

                      I created a few of these templates, depending on the time frame, so none of my charts are "dynamic". For me, I think this helps the overall performance.

                      For more info on creating these time templates, here is a good article:



                      I'd still be interested in that "isLastBar()" function if you don't mind sharing.

                      Daniel
                      eSignal File Share: http://share.esignal.com/groupcontents.jsp?groupid=1130

                      Comment

                      Working...
                      X