Announcement

Collapse
No announcement yet.

Understanding getSeries

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

  • Understanding getSeries

    The new getSeries function looks useful, but I'm having no luck getting it to work. I've looked for examples here in the forum and I've studied the help article. Guess it's time to ask for help.



    Start with a simple test program like -

    Code:
    //***********************
    
       var varX = null;
    
    //***********************
    function preMain(){
       setPriceStudy(true);
       debugClear();
       debugPrintln("*** Test_GetSeries_3 ***");
    }
    //***********************
    function main(){
       varX = test();
    
       return varX;
    }
    //***********************
    function test(){
       var var1 = close() + 5;
    
       return var1;
    }

    This works fine of course. Now I'll modify it to use the getSeries function -

    Code:
    //***********************
    
       var varX = null;
    
    //***********************
    function preMain(){
       setPriceStudy(true);
       debugClear();
       debugPrintln("*** Test_GetSeries_3 ***");
    }
    //***********************
    function main(){
       debugPrintln("A ***");
       varX = test();
       debugPrintln("D");
    
       return new Array(varX.getValue(0), close(0) - 2);
    }
    //***********************
    function test(){
       debugPrintln("B");
       var var1 = close() + 5;
       debugPrintln("C");
    
       return getSeries(var1);
    }
    I expect varX to be a pointer to a time series object, and I expect varX.getValue(n) to return the particular value from that object associated with the bar at index n. However ...

    There are no error messages, but also no output.

    The debug window says "A *** B C A *** B C ..." instead of "A *** B C D A *** B C D ...".


    ???
    Last edited by pflash50; 09-10-2005, 03:44 PM.

  • #2
    pflash50
    You are processing a series which will return a value and not a series. See this post for a brief explanation.
    FWIW you only need to return a series if you want the formula engine to maintain syncronization across multiple intervals or different symbols.
    Alex

    Comment


    • #3
      pflash50
      Try the enclosed revision of your script

      PHP Code:
      //***********************

         
      var varX null;

      //***********************
      function preMain(){
         
      setPriceStudy(true);
         
      debugClear();
         
      debugPrintln("*** Test_GetSeries_3 ***");
      }
      //***********************
      function main(){
         
      debugPrintln("A ***");
         if (
      varX==nullvarX efsInternal("test");
         
      debugPrintln("D");

         return new Array(
      getSeries(varX), close(0) - 2);
      }
      //***********************
      function test(){
         
      debugPrintln("B");
         var 
      var1 close(0) + 5;
         
      debugPrintln("C");

         return 
      var1;

      In the above case you could also simply return varX.getValue(0) from main since you are not running this across multiple intervals or different symbols. If however you passed a series containing inv() or sym() to the external function then you would want to return getSeries(varX) from main as that will allow the formula engine to maintain syncronization with the external interval (as in the following example)
      Alex

      PHP Code:
      //***********************

         
      var varX null;

      //***********************
      function preMain(){
         
      setPriceStudy(true);
         
      debugClear();
         
      debugPrintln("*** Test_GetSeries_3 ***");
      }
      //***********************
      function main(){
         
      debugPrintln("A ***");
         if (
      varX==nullvarX efsInternal("test",inv(5));
         
      debugPrintln("D");

         return new Array(
      getSeries(varX), close(0) - 2);
      }
      //***********************
      function test(interval){
         
      debugPrintln("B");
         var 
      var1 close(0) + 5;
         
      debugPrintln("C");

         return 
      var1;

      Comment


      • #4
        Originally posted by Alexis C. Montenegro

        pflash50
        You are processing a series which will return a value and not a series.
        I have no idea what you are trying to say here.

        Hmmm. I'm not "processing a series" in the first place. I'm processing a sequence of scalar values. Then I'm trying to convert that sequence of values into a series.

        Q) Is this not what the function getSeries is designed to do?


        See this post for a brief explanation.
        I looked at this thread for most of a day before I wrote my cry for help. As far as I can tell it does not address my issue.


        FWIW you only need to return a series if you want the formula engine to maintain syncronization across multiple intervals or different symbols.
        Alex
        FWIW I'm not worried about synchronization across multiple time frames. At least not now.

        But please humor me. Suppose I just want to do this?

        PS - I see another reply, so I'll play with the new suggestions and get back to you. Thanks.
        Last edited by pflash50; 09-10-2005, 07:03 PM.

        Comment


        • #5
          pflash50
          In the following function from your script close() is a series object.

          PHP Code:
          function test(){
             
          debugPrintln("B");
             var 
          var1 close() + 5;
             
          debugPrintln("C");

             return 
          getSeries(var1);

          Once you apply some math to that series (ie you process it) the formula engine retrieves the required value from the series and uses it in the equation. The result is that var1 in your example is not a series but a value hence getSeries(var1) is not applicable as there is no series to retrieve (btw this is what I was explaining in the linked post).

          Q) Is this not what the function getSeries is designed to do?

          No that is not what it is intended to do. The getSeries() function does not create a new series object, but retrieves an already existing one
          In order to create the series you need to call the result of that equation from main or another function using either efsInternal() or efsExternal() which will then create a series as shown in the example I posted in my prior reply.

          Suppose I just want to do this?

          In that case you would use efsInternal() to create the series and you would just return the value ie varX.getValue(0) (see following example)
          Alex

          PHP Code:
          function main(){
             
          debugPrintln("A ***");
             if (
          varX==nullvarX efsInternal("test");
             
          debugPrintln("D");

             return new Array(
          varX.getValue(0), close(0) - 2);

          Comment


          • #6
            Alexis,

            Thank you. The adjusted examples and your additional comments have provided me with the information I was missing. Now I'm going to go play with it for a while.

            Comment

            Working...
            X