Announcement

Collapse
No announcement yet.

Incorrect tick data using getValue()!!!

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Incorrect tick data using getValue()!!!

    Hi Everyone

    I have had trouble getting correct tick data, which synchronized with the Close of the interval.

    For example we use a 1 minute interval chart of say AMZN and get Close of each interval by

    var C = close();

    Suppose we're also interested in 5 latest tick prices. Getting them by

    var C_1Tick_a5 = getValue("close",0,-5,"AMZN,1T");

    And we expect that C_1Tick_a5[0] is equal to C, but I found that is not the case with the following efs:

    /****************************************/
    var Sym, Interval, SymInterval, Sym1T;

    function preMain() {
    setStudyTitle("Data_test");
    setCursorLabelName("C",0);
    setCursorLabelName("C_1Tick",1);
    setCursorLabelName("C_1Tick_a5[0]",2);
    setCursorLabelName("C_1Tick_a5[1]",3);
    setCursorLabelName("C_1Tick_a5[2]",4);
    setCursorLabelName("C_1Tick_a5[3]",5);
    setCursorLabelName("C_1Tick_a5[4]",6);
    setCursorLabelName("10",10);
    setDefaultBarFgColor(Color.teal,0);
    setDefaultBarFgColor(Color.blue,1);
    setDefaultBarFgColor(Color.green,2);
    }
    function main() {
    var nBarState = getBarState();
    if(nBarState == BARSTATE_ALLBARS) {
    Sym = getSymbol();
    Interval = getInterval();
    SymInterval = Sym + "," + Interval;
    Sym1T = Sym + "," + "1T";
    }

    var Real = 0; //Assuming historical data

    // Check for real time calculation
    if(isLastBarOnChart()) {
    Real = 1;
    var C = close();
    var C_1Tick = getValue("close",Sym1T);
    var C_1Tick_a5 = getValue("close",0,-5,Sym1T);
    if(C_1Tick_a5 == null) {return new Array(Real,15);} // Null check
    }
    else {
    return;
    }
    return new Array (C,C_1Tick,C_1Tick_a5[0],C_1Tick_a5[1],C_1Tick_a5[2],C_1Tick_a5[3],C_1Tick_a5[4]);

    }
    /***********************************************/

    I ran tick replay of AMZN data of 08/15/03 using the above efs and found that C_1Tick_a5[0],C_1Tick_a5[1],C_1Tick_a5[2],C_1Tick_a5[3],C_1Tick_a5[4] were not the 5 latest tick prices for any moment of time, particularly at the close of each interval. For example, at 07:21 of 08/15/03 the data (from download file)are:

    T,030815,072107,40.16,100,NMS
    T,030815,072109,40.17,100,NMS
    T,030815,072113,40.16,500,NMS
    T,030815,072114,40.18,200,PSE
    T,030815,072121,40.18,600,PSE
    T,030815,072125,40.18,2000,NMS
    T,030815,072128,40.14,500,CSE
    T,030815,072129,40.14,100,CSE
    T,030815,072142,40.17,100,PSE
    T,030815,072143,40.18,200,PSE
    T,030815,072143,40.18,100,PSE
    T,030815,072143,40.18,100,PSE
    T,030815,072144,40.19,300,PSE
    T,030815,072145,40.19,100,NMS
    T,030815,072145,40.19,100,CSE
    T,030815,072148,40.19,700,PSE
    T,030815,072148,40.19,100,PSE
    T,030815,072148,40.19,100,PSE
    T,030815,072149,40.19,100,CSE
    T,030815,072150,40.19,1000,NMS

    and the data of the first tick of the 07:22 interval are:
    T,030815,072205,40.2,400,NMS

    While, the efs gave:

    C = 40.19 [correct Close]

    but incorrect tick data

    C_1Tick_a5[0] = 40.18 [incorrect, it's the 9th latest, not the latest tick !]
    C_1Tick_a5[1] = 40.18 [incorrect, it's the 10th latest]
    C_1Tick_a5[2] = 40.18 [incorrect, it's the 11th latest]
    C_1Tick_a5[3] = 40.17 [incorrect, it's the 12th latest]
    C_1Tick_a5[4] = 40.14 [incorrect, it's the 13th latest]

    Please help. Thanks.

    Regards
    Dzung Nguyen

  • #2
    Hello Dzung,

    I've identified a problem with the getValue() function vs. close() and will forward the information to our development team.

    It appears that getValue("close", 0, 1, "AMZN,T") returns the second to last tick where close() returns the last tick. The close() function does match time and sales data on a trade-by-trade basis. Below is a modified version of your formula that will display the correct tick data. Basically, I made your array for storing the tick data a global array and used the .pop() .unshift() functions to update the array.

    TickData_dungn6au47.efs
    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
      Hi Jason

      Thanks.
      To get the corresponding times for the lastest 5 tick prices, previously I used

      var Time1T_a5 = getValue("rawtime",0,-5,Sym1T);

      Now, should I continue to use this or it would give me incorrect times as well. If so, please show me how to get the correct corresponding times.

      And to get trade volumes of the 5 ticks previously I used

      var Volume1T_a5 = getValue("volume",0,-5,Sym1T);

      Now, I think I cannot use

      var V = volume() ;

      since it's the accummulative volume of the bar, except for the tick which is the 1st tick of the bar. How can I go around this problem ?

      Regards

      Dzung Nguyen

      Comment


      • #4
        Hello Dzung,

        For time and volume, follow the same process as I used for the tick data. Make the arrays global and use the .pop()/.unshift() routine.

        For time, you could use the following method to build a string and then stuff the value into your time array.

        PHP Code:
        var vDate = new Date();

        var 
        vDate.getHours();
        if (
        10"0" h;

        var 
        vDate.getMinutes();
        if (
        10"0" m;

        var 
        vDate.getSeconds();
        if (
        10"0" s;

        var 
        vTime =  ":" ":" s
        For volume, just use volume() like I used close() in the previous formula.

        By the way, the problem with getValue() was confirmed by the development team and will be fixed for the next public release.
        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
          Hi Dzung,

          I forgot to mention that volume() will give you the total volume for the interval. If you want the volume of the last trade do the following, which will match time and sales size.

          PHP Code:
          var vol1 0;
          var 
          vol2 0;

          function 
          main() {
              if (
          getCurrentBarIndex() == 0) {
                  if (
          getBarState() == BARSTATE_NEWBARvol2 0;
                  
          vol2 vol1;
                  
          vol1 volume();
                  var 
          vTradeVol vol1 vol2;
                  return 
          vTradeVol;
              } else {
                  return;
              }

          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


          • #6
            Hi Dzung,

            I just remembered, we have a new function in the newest version that will give you the size of the last trade. If you are on 7.4, use this for volume.

            PHP Code:
            var vTradeVol getMostRecentTradeSize(); 
            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


            • #7
              Many thanks Jason
              Cheers
              Dzung

              Comment


              • #8
                Hi Jason

                I change my efs to what you suggested. And it works well in real time. With tick replay, it also works for price data, but not for volume and time data. Recent tick volume is always -1, and recent tick time is current local time. Are there ways to go around these problems ?

                Regards
                Dzung

                Comment

                Working...
                X