Announcement

Collapse
No announcement yet.

Question for the EFS experts

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

  • Question for the EFS experts

    According to this thread one cannot use callFunction() to retrieve individual values from a returned array in the called efs.

    In fact if I use the following efs

    PHP Code:
    function preMain() {
        
    setPriceStudy(false);
        
    setStudyTitle("Call-CallFunction test");
        
    setDefaultBarFgColor(Color.blue,0);
        
    setDefaultBarFgColor(Color.red,1);
    }
    function 
    main() {

    var 
    test = new Array(2);
    test callFunction("/Builtin/MAofCCI.efs","main");
    //test = call("/Builtin/MAofCCI.efs");
    test1=test[0];
    test2=test[1];

    return new Array(
    test1,test2);

    to call the returned array in the attached MAofCCI.efs (that I have in the Builtin folder) I get an error as can be seen in the following image.



    Switching call() in place of callFunction() (Lines 10 and 11) then allows me to retrieve the values in the array of the called efs as shown in the following image.



    and even to retrieve them individually as shown in the next image.



    As an aside not only do both plots of MAofCCI.efs appear but also the bands set by addBand in the called efs. Would not mnind knowing why but it is beside the issue I am trying to solve.

    (continues on next message)
    Attached Files

  • #2
    (continued from prior message)

    However, if I use the attached Preferred Stochastic.efs (from the DiNapoli folder) as the called efs then callFunction() works while call() does not.
    Here is the calling efs again with the callFunction() line active and the call() line commented out.

    PHP Code:
    function preMain() {
        
    setPriceStudy(false);
        
    setStudyTitle("Call-CallFunction test");
        
    setDefaultBarFgColor(Color.blue,0);
        
    setDefaultBarFgColor(Color.red,1);
    }
    function 
    main() {

    var 
    test = new Array(2);
    test callFunction("/DiNapoli/Preferred Stochastic.efs","main");
    //test = call("/DiNapoli/Preferred Stochastic.efs"");
    test1=test[0];
    test2=test[1];

    return new Array(
    test1,test2);

    And here below is the result



    The values in the returned array can be called individually even though I am using callFunction()



    (continues on next message)
    Attached Files

    Comment


    • #3
      (continued from prior message)

      If instead I use the DiNapoli MACD neither call() nor callFunction() will work and in both case will return an error.
      Here once again the calling efs while attached is the DiNapoli MACD (located in the DiNapoli folder)

      PHP Code:
      function preMain() {
          
      setPriceStudy(false);
          
      setStudyTitle("Call-CallFunction test");
          
      setDefaultBarFgColor(Color.blue,0);
          
      setDefaultBarFgColor(Color.red,1);
      }
      function 
      main() {

      var 
      test = new Array(2);
      test callFunction("/DiNapoli/MACD.efs","main");
      //test = call("/DiNapoli/MACD.efs");
      test2=test[0];
      test2=test[1];

      return new Array(
      test1,test2);

      The only way I can retrieve the values of the called efs is with the following modification which does not however allow me to retrieve the individual plots.

      PHP Code:
      function preMain() {
          
      setPriceStudy(false);
          
      setStudyTitle("Call-CallFunction test");
          
      setDefaultBarFgColor(Color.blue,0);
          
      setDefaultBarFgColor(Color.red,1);
      }
      function 
      main() {

      //var test = new Array(2);
      test callFunction("/DiNapoli/MACD.efs","main");
      //test = call("/DiNapoli/MACD.efs");
      //test2=test[0];
      //test2=test[1];

      return test;//new Array(test1,test2);



      Can anyone explain the reasons to these differences in behavior of call() and callFunction()?
      Also, how does one then identify which called efs may work with one or the other calling method?
      Why don't call() or callFunction() work with DiNapoli MACD?
      Lastly how did the bands get added to the efs calling the Preferred Stochastic?
      TIA
      Alex
      Attached Files

      Comment


      • #4
        Hi Alex,

        My guess is that because you are declaring your array before using call() or callfunction() that you sometimes get a benefit from an optimzation/artifact in the c compiler. I bet if you took a debugger to the c code you would find that sometimes when the data aligns on the proper boundaries (a page?) you are getting extra data transfered.

        For sure this shouldn't be working in ANY case, as the engineer who wrote it said that he never took into account arrays...though he was going to add fixing this onto his list.

        Garth
        Garth

        Comment


        • #5
          Garth
          That this is a result of some artifact/optimization is likely confirmed by the fact that as of now Preferred Stochastic has been the only efs I managed to call using callFunction().
          That aside any idea as to why call() would not work with DiNapoli MACD?
          Alex

          Comment


          • #6
            Hi Alex,

            I started the thread Garth refers to, as I had the same problem as you.
            The conclusion was that, like Garth said, none of these should work, although sometimes they do.
            Note: One time I was told that callFunction() is like having the function within your efs, which makes a lot of sense and would be really useful, but looks like it did not turned out that way.

            The diference between call(0 and callFunction(0 is that call call() is treated like a study (runs for all bars irespective of any other conditions), whereas callFunction is called for each bar, as they are formed.

            Consequentelly, in cll() one cannot feed dynamic inputs (like a MA, for example), but this is possible using callFunction().


            Hope this helps.
            Mihai
            Mihai Buta

            Comment


            • #7
              Alex,

              Try this:

              PHP Code:
              function preMain() {
                  
              setPriceStudy(false);
                  
              setStudyTitle("Call-CallFunction test");
                  
              setDefaultBarFgColor(Color.blue,0);
                  
              setDefaultBarFgColor(Color.red,1);
              }
              function 
              main() {

                  
              // var test = new Array(2);
                  // test = callFunction("/DiNapoli/MACD.efs","main");
                  
              test call("/DiNapoli/MACD.efs");
                  
              //test2=test[0];
                  //test2=test[1];
              // return new Array(test1,test2);
              return(test);

              For me it gets both the signal and MACD lines, but if I comment out the test2=test[0]; line I get an error. Go figure.

              I think there is something here eSignal need to look into.

              Garth
              Garth

              Comment


              • #8
                but if I comment out the test2=test[0];
                Errr...I mean uncomment the statement...
                Garth

                Comment


                • #9
                  Garth
                  Yes, it behaves like callFunction and retrieves both values of the array but as soon as you try to retrieve only one value it says the object has no properties.
                  The question (for me at least) is to find the way to consistently write an efs that returns an array that when called will allow its values to be retrieved separately (assuming this is even the issue).
                  Alex

                  Comment


                  • #10
                    Alex,

                    The question (for me at least) is to find the way to consistently write an efs that returns an array that when called will allow its values to be retrieved separately (assuming this is the issue).
                    I think, at least for now, it's a "you can't there from here".

                    However, I think the fact that you can't count on the behavior of call or callFunction when the called formula returns an array puts this is a category of a bug, and is separate from the enhancement request that is already pending.

                    The fact that the enhancement may well fix the bug, just means that the enhancement should be raise in the priority queue.

                    Garth
                    Garth

                    Comment


                    • #11
                      Hello All,

                      The missing element that will solve all your problems is a null check. When using call() or callFunction(), a null check needs to be performed to ensure that valid data was returned. With our built-in studies, it's a good habit to check for nulls as well. Especially if your formula is doing some math with the use of the built-in study's return values.

                      What's happening with your code example Alex is that the DiNapoli MACD.efs needs 18 bars of data before it can return a valid array of data. So when you do test1 = test[0]; you get an error on the oldest bar, or first bar the formula executes on, because test is not a valid array at that point. I probably don't need to say anymore for Alex or Garth, but for the other members of the community I'll complete this example for the sake of education.

                      To illustrate this, I've set up a time template to only load 90 daily bars. I added the following line of code just above the return statement from Alex's code example so you can see the result of test on a bar by bar basis as the formula loads.

                      PHP Code:
                      debugPrintln(getCurrentBarIndex() + " " test); 
                      Here’s the result in the Formula Output Window.


                      As you can see, bar -61 is the oldest bar in my chart, so from that bar to bar -44 (18 bars) MACD.efs returns null.

                      Here's the modified version of Alex's code with a null check. Note, you can use call() or callFunction() with this example.

                      PHP Code:
                      function preMain() {
                          
                      setPriceStudy(false);
                          
                      setStudyTitle("Call-CallFunction test");
                          
                      setDefaultBarFgColor(Color.blue,0);
                          
                      setDefaultBarFgColor(Color.red,1);
                      }


                      function 
                      main() {
                          
                          var 
                      test null;

                          
                      //test = call("/DiNapoli/MACD.efs");
                          
                      test callFunction("/DiNapoli/MACD.efs""main");

                          
                      //debugPrintln(getCurrentBarIndex() + " " + test);
                          
                      if (test == null) return;
                          
                          var 
                      test1 test[0];
                          var 
                      test2 test[1];
                          return new Array(
                      test1,test2);
                          
                      //return(test);

                      Here's my chart.


                      A note on when to use call() vs. callFunction(). My rule of thumb is to always use callFunction() unless the formula I'm calling requires the use of it's own global variables where those values get manipulated with subsequent iterations of the formula. callFunction() is a little more efficient than call().

                      callFunction() will just execute the function requested. If the function uses any global variables in it's code block, it uses their default values.
                      call() loads the formula as if it were applied to the chart, with the exception that the preMain() settings won't affect your chart. So "main" is being called by default with call() and is able to make use of the formula's global variables.

                      Hope this helps.
                      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


                      • #12
                        JasonK,

                        You make an excellent point on checking for nulls...I am surprised I forgot about this since it has bitten me before in exactly the same way.

                        However, this still doesn't explain why I can sometimes get more than a one element return and sometimes I can only get one element, when calling a function that returns an array.

                        Very strange that...

                        Garth
                        Garth

                        Comment


                        • #13
                          Jason and Garth
                          My thanks to the both of you for coming to my support.
                          This was indeed a very interesting learning experience.
                          Alex

                          Comment


                          • #14
                            Garth, that is strange. I'm not sure why that would be happening. Can you put together a code example to illustrate the problem? I'd be more than happy to investigate.
                            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


                            • #15
                              Hi Jason and Garth,

                              The same subject was discussed in two other threads and at that time it seemed that things were very clear (both of you participated):

                              1. callFunction cannot pass the name of a study or array.
                              2. callFunction was not designed to access individual returned values (although you can plot the entire array).

                              M
                              Mihai Buta

                              Comment

                              Working...
                              X