Announcement

Collapse
No announcement yet.

sym() in EFS2

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

  • sym() in EFS2

    I just found that for some reason it seems using sym() and getValue() can not align data quotes correctly in realtime. To illustrate what problem I ran into, I wrote a testing script.
    Run it on any one of "YM H7,1", "ES H7,1", "NQ,1" or "AB H7" and wait for a few minutes. The script will only print out the first abnormal instance it found.

    The attached sample screenshot was captured when the script was running on "YM H7,1" At the moment of the beginning of the bar at 12:27, the quotes of the open and close prices of the
    bar at 12:25 was returned as that of bar 12:26.

    Only interesting thing is that in the case of setComputeOnClose(), the similar method always returns the correct values (in stead of returning one bar shifted values in some cases as shown in my attached example.

    Anyone knows what is the reason and if it is really a bug in EFS2, is there a work around fix?

    //************************************************** *
    // Script Name: sym_testing.efs
    //************************************************** *

    var symbols;

    var bInit;

    var aOpen, aClose;

    var n;

    var found = false;

    function preMain() {
    setPriceStudy(false);
    setStudyTitle("ATS_sym_testing");
    setShowCursorLabel(false);
    }

    function main( ) {

    var i, j;
    if ( getBarState() == BARSTATE_ALLBARS ) {

    setStudyMax(100);
    setStudyMin(0);

    symbols = new Array(4);
    symbols[0] = "ES H7";
    symbols[1] = "YM H7";
    symbols[2] = "AB H7";
    symbols[3] = "NQ H7";

    for ( i = 0; i < symbols.length; i ++ ) {
    var S = getSymbol();
    var S2 = symbols[i].substring(0, 2);
    if ( S.indexOf(S2) == 0 ) {
    n = i;
    }
    }


    bInit = false;

    if ( bInit == false ) {
    bInit = true;
    aOpen = new Array(symbols.length);
    aClose = new Array(symbols.length);
    for ( i = 0; i < symbols.length; i ++ ) {
    aClose[i] = close(sym(symbols[i]));
    aOpen[i] = open(sym(symbols[i]));
    //debugPrintln(aOpen[i].getValue(0));
    }
    }

    }


    if ( getBarState() == BARSTATE_NEWBAR && getCurrentBarIndex() == 0 ) {
    if ( found == false ) {
    var h = hour(-1);
    var m = minute(-1);
    for ( i = 0; i < symbols.length; i ++ ) {
    if ( found == false ) {
    var o = aOpen[i].getValue(-1);
    var c = aClose[i].getValue(-1);
    var H = getValueAbsolute("Hour", 0, -3, symbols[i]+",1");
    var M = getValueAbsolute("Minute", 0, -3, symbols[i]+",1");
    var O = getValueAbsolute("Open", 0, -3, symbols[i]+",1");
    var C = getValueAbsolute("Close", 0, -3, symbols[i]+",1");
    if ( M[0] == m ) {
    if ( O[0] != o || C[0] != c ) {
    found = true;
    if ( O[1] == o && C[1] == c ) {
    debugPrintln(symbols[i] + " " + h + ":" + m + " actual quotes: c = " + C[0].toFixed(2) +" o = " + O[0].toFixed(2) + " sym results: c = " + c.toFixed(2) + " o = " + o.toFixed(2) + ", which are equal to quotes at " + H[1]+ ":"+M[1]);
    }
    else {
    debugPrintln(symbols[i] + " " + h + ":" + m + " actual quotes: c = " + C[0].toFixed(2) +" o = " + O[0].toFixed(2) + " sym results: c = " + c.toFixed(2) + " o = " + o.toFixed(2) );
    }
    }
    }
    else if ( M[1] == m ) {
    if ( O[1] != o || C[1] != c ) {
    found = true;
    if ( O[2] == o && C[2] == c ) {
    debugPrintln(symbols[i] + " " + h + ":" + m + " actual quotes: c = " + C[1].toFixed(2) +" o = " + O[1].toFixed(2) + " sym results: c = " + c.toFixed(2) + " o = " + o.toFixed(2) + ", which are equal to quotes at " + H[2]+ ":"+M[2]);
    }
    else if ( O[0] == o && C[0] == c ) {
    debugPrintln(symbols[i] + " " + h + ":" + m + " actual quotes: c = " + C[1].toFixed(2) +" o = " + O[1].toFixed(2) + " sym results: c = " + c.toFixed(2) + " o = " + o.toFixed(2) + ", which are equal to quotes at " + H[0]+ ":"+M[0]);
    }
    else {
    debugPrintln(symbols[i] + " " + h + ":" + m + " actual quotes: c = " + C[1].toFixed(2) +" o = " + O[1].toFixed(2) + " sym results: c = " + c.toFixed(2) + " o = " + o.toFixed(2) );
    }
    }
    }
    }
    }
    debugPrintln(" ");
    }
    }

    }
    //************************************************** *
    // End of the script
    //************************************************** *
    Attached Files

  • #2
    Better formatted Script file.
    Attached Files

    Comment


    • #3
      Another testing script file

      This one is simpler.
      The basic problem is that in the case of retrieving the quote of second symbol, when the getBarState() is equal to BARSTATE_NEWBAR, close(-1, sym(secondSymbol)), etc. does not always returns the quotes corresponding to the bar just finished. Sometimes it returns the quote two bars older. It depends on at the moment getBarState() == BARSTATE_NEWBAR, whether the second symbol has already had quote corresponding to this new bar or not.

      I will attach the screenshot in the next post.
      Attached Files

      Comment


      • #4
        Clearpicks,

        As far as I know to correctly access another interval from the base interval of the chart you would specify the interval via the inv() parameter, similiar to accessing external symbols via the sym() parameter.

        I don't think the same functionality is available by specifying the time interval as the last parameter in the symbol specification.

        Glen
        Glen Demarco
        [email protected]

        Comment


        • #5
          From the screenshot it can be seen that at the beginning of 14:17, 14:16 etc. close(-1, sym("ES H7")) returns the wrong quote, while at the beginning of 14:18, it returns the correct one.

          By analyzing the detailed time and sales of the primary and second symbols, it seems when getBarState() == BARSTATE_NEWBAR, if at this moment, the second symbol still does not have trade coming, close(-1, sym("secondSymbol") would return the wrong value. For example,

          21 23 ES H7 14:23:02 1430.25 YM H7 14:23:02 12518
          15 17 ES H7 14:17:02 1430.00 YM H7 14:17:01 12517


          18 19 ES H7 14:19:00 1430.00 YM H7 14:19:00 12518
          17 18 ES H7 14:18:04 1430.00 YM H7 14:18:13 12518
          Attached Files

          Comment


          • #6
            Glen
            The sym() function can set the symbol or symbol and interval.
            For the description and syntax you may want to see this article in the EFS KnowledgeBase
            Alex


            Originally posted by demarcog
            Clearpicks,

            As far as I know to correctly access another interval from the base interval of the chart you would specify the interval via the inv() parameter, similiar to accessing external symbols via the sym() parameter.

            I don't think the same functionality is available by specifying the time interval as the last parameter in the symbol specification.

            Glen

            Comment


            • #7
              Alex,

              Oops, forgot about that, I've only been using inv() lately.

              Sorry about that, the last thing I want to do is provide incorrect infomation, maybe I should cut back on responding.

              Thank you very much for correcting that so quickly.
              Glen Demarco
              [email protected]

              Comment


              • #8
                clearpicks
                To determine the BARSTATE_NEWBAR of an external symbol (or symbol/interval) try using getBarStateSymbol()
                Alex

                Comment


                • #9
                  Alex,

                  I do not want to access the bar state of the second symbol. My example just tries to point out that close(xxx, sym()) may returns
                  incorrect values in certain transient state. For those historical bars, it always works. However in realtime, it may returns incorrect values. If some trading signals are just triggered at the moment (tha tis, when getBarState() == BARSTATE_NEWBAR and getCurrentBarIndex() == 0), it may cause some problems.

                  - Clearpicks


                  Originally posted by Alexis C. Montenegro
                  clearpicks
                  To determine the BARSTATE_NEWBAR of an external symbol (or symbol/interval) try using getBarStateSymbol()
                  Alex

                  Comment


                  • #10
                    Hello Clearpicks,

                    This is not a bug. What you are dealing with is simply the timing of trades between two different symbols. The NEWBAR state will not always occur at exactly the same time between two symbols, which seems to be your expectation. This state is triggered on the first trade that occurs within the 1-minute window when using a 1-minute chart. You may be expecting the NEWBAR state to occur based on the change of the clock. For example, let's say the first trade for symbol1 occurs at 09:00:01, the first second of the 1-minute interval that starts at 09:00:00. If this is the main chart symbol, hour(0) + ":" + minute(0) returns 9:00. If symbol2 has not yet traded after 09:00:00 and you retrieve the time stamp, hour(0, sym("symbol2")) + ":" + minute(0, sym("symbol2")), it will refer to 08:59:00 as this is the current bar 0 for symbol2 at 09:00:01. The result will give you a 1 bar difference in time stamps. There isn't a code example that can force the time stamps to always be in synch with each other. The only way this would occur is if the two symbols always traded at exactly the same time. Please let me know if you do not understand this issue.
                    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


                    • #11
                      Hello Jason,

                      I expect getCurrentBarState() returns bar status only based on the primary symbol, right? For example, the primary chart symbol is "ES H7,1" and there is a second symbol "YM H7,1" working because there is a line in the script

                      var aCloseYM = close(sym("YM H7,1"));

                      Suppose after 10:00:00, the first incoming tick of ES H7 arrives at 10:00:10 while the first incoming tick of YM H7 arrives at 10:00:05, I expect getCurrentBarState() == BARSTATE_NEWBAR is true only at 10:00:10 when ES tick arrives. When YM tick arrives at 10:00:05, getCurrentBarState() should still returns BARSTATE_CURRENTBAR because on the chart a new candlestick bar for the time period 10:00:00 to 10:00:59 has not been drawn, am I right?

                      Anohter question which ight be related to this issue is how main() is triggered (called) when setComputeOnClose()? Is it called whenever a primary symbol transaction occurs with time stamp for the next new minute or any trasaction of any symbols (being processed by the script) with a timestamp in next new minute will represent the end of the current candlestick bar and triggers the main() function (with getCurrentBarIndex() returns -1).

                      Could you answer these two questions?

                      - Clearpicks



                      Originally posted by JasonK
                      Hello Clearpicks,

                      This is not a bug. What you are dealing with is simply the timing of trades between two different symbols. The NEWBAR state will not always occur at exactly the same time between two symbols, which seems to be your expectation. This state is triggered on the first trade that occurs within the 1-minute window when using a 1-minute chart. You may be expecting the NEWBAR state to occur based on the change of the clock. For example, let's say the first trade for symbol1 occurs at 09:00:01, the first second of the 1-minute interval that starts at 09:00:00. If this is the main chart symbol, hour(0) + ":" + minute(0) returns 9:00. If symbol2 has not yet traded after 09:00:00 and you retrieve the time stamp, hour(0, sym("symbol2")) + ":" + minute(0, sym("symbol2")), it will refer to 08:59:00 as this is the current bar 0 for symbol2 at 09:00:01. The result will give you a 1 bar difference in time stamps. There isn't a code example that can force the time stamps to always be in synch with each other. The only way this would occur is if the two symbols always traded at exactly the same time. Please let me know if you do not understand this issue.

                      Comment


                      • #12
                        Hello clearpicks,

                        Originally posted by clearpicks
                        Hello Jason,

                        I expect getCurrentBarState() returns bar status only based on the primary symbol, right? For example, the primary chart symbol is "ES H7,1" and there is a second symbol "YM H7,1" working because there is a line in the script

                        var aCloseYM = close(sym("YM H7,1"));
                        Correct, getBarState() refers to main chart symbol only.

                        Suppose after 10:00:00, the first incoming tick of ES H7 arrives at 10:00:10 while the first incoming tick of YM H7 arrives at 10:00:05, I expect getCurrentBarState() == BARSTATE_NEWBAR is true only at 10:00:10 when ES tick arrives. When YM tick arrives at 10:00:05, getCurrentBarState() should still returns BARSTATE_CURRENTBAR because on the chart a new candlestick bar for the time period 10:00:00 to 10:00:59 has not been drawn, am I right?
                        Correct, getBarState() will return BARSTATE_CURRENTBAR in this case.

                        Anohter question which ight be related to this issue is how main() is triggered (called) when setComputeOnClose()? Is it called whenever a primary symbol transaction occurs with time stamp for the next new minute or any trasaction of any symbols (being processed by the script) with a timestamp in next new minute will represent the end of the current candlestick bar and triggers the main() function (with getCurrentBarIndex() returns -1).

                        Could you answer these two questions?

                        - Clearpicks
                        Your understanding of setComputeOnClose() in this case appears to be correct as well.
                        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