Announcement

Collapse
No announcement yet.

Call Function: variable input parameters.

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

  • Call Function: variable input parameters.

    Hi,

    Are there any rules/restriction regarding input parameters for external functions?
    I have some functions that work in a large EFS, but some do not work when I try to move them out and call them.

    I identified that the problem occur only when parameters are variables, like a moving average for example.

    For example:

    var xyz = call("xxx.efs", MAS10, prevMAS10)

    Again, the function works when is part of the file where MAS10 is generated.

    Can anybody help? Thanks.
    Mihai Buta

  • #2
    mbuta,

    There shouldn't be a problem with using variables as parameters to call() or callFunction().

    Maybe you can give a bit more details - like what seems to not work (errors, odd results, no results) and better yet a very small test case of a calling EFS and a called EFS with variable that doesn't work.

    If you come up with a small example - I would be happy to look at it. I am using callFunction (instead of call) - but have no problem at all with using variables and even arrays as paramters.

    Garth
    Garth

    Comment


    • #3
      Re: Reply to post 'Call Function: variable input parameters.'

      Hi Garth,
      Thank you for your reply.
      When I pass a variable as parameter, like a MA which a study in my EFS,
      looks like it gets stuck in a loop. No message, but the clepsidra stays on
      forever.

      Here is an examples, but I tried several others, with the same result:
      call("MyFuctions/Slope.efs, MAS10, prevMAS10, SlopeLength)

      where MAS10, and prevMAS10 are the current and a previous value (get...) of
      the 10 bars moving average.
      The function itself is the slope fucntion you guys published, in other
      words, a simple calculation.
      Please note that ALL functions I refer to, work as part of a large efs
      study.

      One more thing (other anomaly):
      I also have a "SlopeLength.efs" function, which is a simple Math.min(4,
      .25*MALength).
      I tried to reduce the overhead by calling this function only once at
      "ALLBARS" time, but did not recognize it.
      Note: For my original problem, I eliminated the nesting of call functions,
      by making the SlopeLength a constant.

      Thank you.

      ----- Original Message -----
      From: <[email protected]>
      To: <[email protected]>
      Sent: Friday, August 22, 2003 8:51 AM
      Subject: Reply to post 'Call Function: variable input parameters.'


      > Hello mbuta,
      >
      > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      >
      Mihai Buta

      Comment


      • #4
        Hi,

        Here is an examples, but I tried several others, with the same result:

        call("MyFuctions/Slope.efs, MAS10, prevMAS10, SlopeLength)
        OK, I'm assuming that the lack of an ending " for the function name and the missing ; for the end of statement are just type-o's.

        The function itself is the slope fucntion you guys published, in other
        I'm not sure who "you guys are". Alex, Chris, Brad, someone from eSignal (Jay, Jason)? Maybe you can point me to the function and I will write a simple caller program.

        Let me describe a few things about call() and callFunction() that may help you.

        When you use call() vs. callFunction() eSignal iterates all it for all the bars in the chart, and then continues with the calling function. The results of the called function are stored and available for each new bar when it is requested. If you change any of the parameters in the call(), then a new version of the called EFS is instantiated and iterated for all the bars in the chart.


        What this means to you, is that if you have a LOT of bars and a complex function, it could take a long while for it to instantiate and iterate through the bars. If you call it with different parameters each time (ie: the value of the variables in the call change) then it can take a VERY long time since it will have to do this each time the variables aren't the same as one it has done already.

        When I am debugging called functions, I usually do a few steps. They are obvious, but I will bring it up anyway. Step 1 is to verify the called function can execute on it's own without error. Sometimes this means adding extra code so that it can run standalone, but it is worth the effort.

        You can also use debugPrint() and debugPrintln() in the called efs. With this you can verify it is being called, that the parameters passed to it are the ones you expected, and that you are getting the return value it thinks its passing you.

        Garth
        Garth

        Comment


        • #5
          Hi Garth,

          I attach one of the files that generate the "problem" and I have many others if needed. Move the "Slope" function outside, use a call and you have it.

          I believe that you will find out that there is nothing wrong with the code, but it is a serious EFS limitation, created by the "innovative" way to process studies and calls (runs them for all bars first), which creates several other limitations.

          If this turns out to be the case, calling function is non-existent for practical reasons in EFS and nesting calls is completelly out the question!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

          Here it is:

          var studyMAS10 = new MAStudy(10, 0, "Close", MAStudy.SIMPLE);
          var studyMAS20 = new MAStudy(20, 0, "Close", MAStudy.SIMPLE);
          var studyMAS50 = new MAStudy(50, 0, "Close", MAStudy.SIMPLE);

          function preMain() {
          setPriceStudy(false);
          setCursorLabelName("SlopeMA50", 0);
          setCursorLabelName("SlopeMA20", 1);
          setCursorLabelName("SlopeMA10", 2);
          setDefaultBarFgColor(Color.red, 1);
          setDefaultBarFgColor(Color.lime, 2);
          setPlotType(PLOTTYPE_HISTOGRAM, 0);
          }

          function main(ShowDayNormalized, IncludeMA10, IncludeMA20, IncludeMA50, ShowWeighted, SlopeTrendLevel) {
          if (ShowDayNormalized==null) ShowDayNormalized=1;
          if (IncludeMA10==null) IncludeMA10 = 1;
          if (IncludeMA20==null) IncludeMA20 = 1;
          if (IncludeMA50==null) IncludeMA50 = 1;
          if (ShowWeighted==null) ShowWeighted=0;
          if (SlopeTrendLevel==null) SlopeTrendLevel=.5;

          setStudyTitle("Slopex3(.25MA)MA: 10/20/50"+".Norm="+ShowDayNormalized+
          ".Weighted="+ShowWeighted+".Trend@"+SlopeTrendLeve l);
          var sInterval = getInterval();
          var nBarState = getBarState();
          if (nBarState == BARSTATE_ALLBARS) {
          }


          var MA10 = studyMAS10.getValue(MAStudy.MA);
          var MA20 = studyMAS20.getValue(MAStudy.MA);
          var MA50 = studyMAS50.getValue(MAStudy.MA);
          var slopeMA10 = Slope(MA10, studyMAS10.getValue(MAStudy.MA, -SlopeLength(10)), SlopeLength(10));
          var slopeMA20 = Slope(MA20, studyMAS20.getValue(MAStudy.MA, -SlopeLength(20)), SlopeLength(20));
          var slopeMA50 = Slope(MA50, studyMAS50.getValue(MAStudy.MA, -SlopeLength(50)), SlopeLength(50));


          //DayNormalization
          var NumberOfBarsPerDay;
          if (sInterval <= 60) {
          NumberOfBarsPerDay = Math.round(6.5*60/sInterval);
          } else {NumberOfBarsPerDay = 1;}
          if (ShowDayNormalized !=0) {
          slopeMA10 *= NumberOfBarsPerDay;
          slopeMA20 *= NumberOfBarsPerDay;
          slopeMA50 *= NumberOfBarsPerDay;
          }
          //Adjust for MA "weight"
          if (ShowWeighted !=0) {
          slopeMA10 *= 1;
          slopeMA20 *= 2;
          slopeMA50 *= 5;
          }

          //{{EFSWizard_Return
          var ReturnedSlope = slopeMA50*IncludeMA50;

          if (ReturnedSlope > SlopeTrendLevel) {setDefaultBarFgColor(Color.lime, 0);}
          else if (ReturnedSlope < -SlopeTrendLevel) {setDefaultBarFgColor(Color.red, 0);}
          else {setDefaultBarFgColor(Color.cyan, 0);}

          return new Array(ReturnedSlope, slopeMA20*IncludeMA20, slopeMA10*IncludeMA10);
          //}}EFSWizard_Return 4922

          }

          function Slope(Point1, Point2, SlopeLength) {
          if (SlopeLength == null) {SlopeLength = 1;}
          var nSlope = 100*(Point1-Point2)/Point1;
          nSlope = nSlope/SlopeLength;
          return (nSlope);
          } //End Slope function

          function SlopeLength(MALength) {
          var SlopeLength = Math.min(10, Math.round(.25*MALength));
          return SlopeLength;
          }
          Mihai Buta

          Comment


          • #6
            Hi Mihai,

            I will look things over this weekend and see what I can see.

            call() does things that way for a good reason. If it didn't do it this way, the values returned might be very differnt than those you expected.

            However because of the overhead it creates, I specifically asked for callFunction() to be created. It doesn't interate over all the bars once it is called, instead it acts more like a macro or a #include. This may be more what you are looking for. However, it too has a bit of a downside in that if the called function uses things like ref() it will not get the results you want.

            Garth
            Garth

            Comment


            • #7
              Hi Mihai,


              Yes, you are right, the call function is the killer here, since the MA changes on a regular basis.

              However I changed the EFS to then use callFunction and it worked fine and with the same results as it did when slope was in the main EFS.

              Attached are my files...
              Attached Files
              Garth

              Comment


              • #8
                and the slope function.
                Attached Files
                Garth

                Comment


                • #9
                  Thanks, Garth,

                  I already changed to call function in most places.
                  Mihai Buta

                  Comment

                  Working...
                  X