Announcement

Collapse
No announcement yet.

problem with getBarState()

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

  • problem with getBarState()

    My efs has been relying on getBarState() to return the BARSTATE_NEWBAR (numerical value = 0) when a new bar is arriving. I just found out that sometimes getBarState() returns 1 (BARSTATE_CURRENTBAR), not 0, when the first tick of a new bar is arriving. I attach a test efs. I ran a tick replay of AMZN data of 10/27/03 @ interval of 5000V with this efs. getBarState() failed to recognise new bar state for a couple of bars (e.g. bar 53, 95, 239, ...)

    eSignal Technical Support Specialists please verify the problem. T

    Dzung Nguyen
    Attached Files

  • #2
    I use the following code to accomplish the same thing..

    PHP Code:
    var nLastRawTime 0;
    var 
    BarCount 0;


    function 
    main() {

     if (
    nLastRawTime != getValue("rawtime"0)) {
     
    //  new bar
         
    BarCount += 1;
         
    nLastRawTime getValue("rawtime"0);
     }


    Maybe this will help solve the problem.
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Hi Brad

      Your coding would work with "time" intervals; with "volume" intervals my guess is it won't, right ? Anyway, thanks.

      Dzung
      Last edited by dungn6au47; 10-28-2003, 04:13 AM.

      Comment


      • #4
        Dzung,

        Yes, it will work. I have been using this method myself for a while and have found it to be quite effective. The getValue("rawtime", 0) command updates "rawtime" when a new bar is formed and maintains the same value throughout bar formation. It is a time stamp, in effect, that does not change until the arrival of a new bar. It does not matter what parameter (e.g. - time, tick, volume, price change, ...) you are using as the basis for bar formation, as it only changes when a new bar comes.

        Comment


        • #5
          Hi Steve & Brad

          I tried what you two suggested. It seems to work at first (chart 3), then not working (chart 4). Any ideas what's causing this problem ?

          Dzung
          Attached Files

          Comment


          • #6
            chart4
            Attached Files

            Comment


            • #7
              And the efs:

              var nLastRawTime = 0;
              var BarIndex = 0;
              var C, C1;

              function preMain() {
              // setStudyTitle("Test_BarIndex[rawtime]");
              setPriceStudy(true);
              /* setCursorLabelName("C",0);
              setDefaultBarFgColor(Color.black,0);
              setDefaultBarThickness(2,0);
              */

              }
              function main() {
              C1 = C;
              C = close();
              if (nLastRawTime != getValue("rawtime", 0)) {
              BarIndex += 1;
              DrawCntr = "X" + BarIndex;
              drawLineRelative(-1, C1, -1, C1, PS_DOT, 8, Color.red, DrawCntr);
              nLastRawTime = getValue("rawtime", 0);
              }
              return;
              }

              Comment


              • #8
                Hello Dzung,

                This drift you are seeing is a known problem. Our development is working on a solution. Not sure if it will be fixed for 7.5.
                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


                • #9
                  Hi Jason

                  Did you mean that currently it is a problem even with version 7.5 Beta and the development team is still working on a solution ? And therefore not sure whether it will be fixed prior to the release of version 7.5 in mid November ?

                  Dzung

                  Comment


                  • #10
                    Dzung,

                    The problem you are now seeing in playback mode oddly is because you are using
                    if (nLastRawTime != getValue("rawtime", 0)) {
                    in playback mode. I believe you are getting some bars that are coming in simultaniously and as such, this test does not pick them up as individual bars. here is my code which has a test for playback mode which excludes
                    if (nLastRawTime != getValue("rawtime", 0)) {
                    in playback mode


                    PHP Code:
                    function main() {
                      var 
                    BarState getBarState();
                      
                    nIndex getCurrentBarIndex();    //debugPrintln("nIndex = " +nIndex); 

                            
                        
                        //----------------------------------------------------------------------------------------     
                        
                    if (nIndex < -120){return;} // minimizes load time
                        
                    var i;var j;  var k;  var 0;
                      if (
                    isPlayBackMode()==1){nLastRawTime getValue("rawtime",0);}//for playback mode
                        
                    if (getValue("rawtime",0) != nLastRawTime || BarState == BARSTATE_NEWBAR) {     
                            
                    nLastRawTime getValue("rawtime",0);
                            
                    tTime nTime();//tTime [0] = milliseconds, [1] = h:m:s, [2] = MM-DD-YYYY, [3] = h, [4] = m, [5] = s, [6] = Total s.
                            //var nArray  = getValueAbsolute( "Close", 0, -25 );
                            
                    for (i=0;i<25;i++){nArray[i]= close(-i);}
                            
                    barcount +=1;//debugPrintln("barcount = " +barcount); 
                    see if that works for you.

                    Comment


                    • #11
                      Dzung,

                      To continue, In RT, I use the following conditional which checks for both rawtime change and BarState
                      PHP Code:
                      if (getValue("rawtime",0) != nLastRawTime || BarState == BARSTATE_NEWBAR) { 
                      This has been very reliable for me.

                      In Playback, I had all kinds of problems with just using
                      PHP Code:
                      getValue("rawtime",0
                      so I added the BarState into the conditional and put a step in front of the conditional which takes rawtime out of the picture while in Playback mode. Clear as mud eh?

                      Comment

                      Working...
                      X