Announcement

Collapse
No announcement yet.

%R of EMA using Wizard

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

  • #16
    There are some bugs in this code - not sure where

    I used to following code to create the first efsExternal which could be used in the second efs
    function preMain(){
    setPriceStudy(false);
    setStudyTitle("Fast EMA20-EMA5");
    setCursorLabelName("EMA");

    var fp1 = new FunctionParameter("Series", FunctionParameter);
    fp1.setName("EMA1 - EMA2");
    fp1.setLowerLimit(1);
    fp1.setUpperLimit(200);
    fp1.setDefault(20);
    }

    var myAvg = null;

    function main(Series){//add the parameter to the main definition

    if(myAvg==null) myAvg = (ema (20) -ema (5));//replace the value with the parameter variable

    return myAvg.getValue(0);
    }

    /////////////////////////////////////////////////////////////////////////


    The following is the code that I used to call on the efsExternal
    setCursorLabelName("Fast TA");

    var fp1 = new FunctionParameter("Length", FunctionParameter);
    fp1.setName("Length of %R");
    fp1.setLowerLimit(1);
    fp1.setUpperLimit(200);
    fp1.setDefault(20);
    }

    var myAvg = null;
    var ext = null

    function main(Length){//add the parameter to the main definition

    ext=efsExternal ("Step1Ext.efs")


    if(myAvg==null) myAvg = percentR((Length),ext);//replace the value with the parameter variable

    return myAvg.getValue(0);
    }

    Comment


    • #17
      There are some bugs in this code - not sure where

      global
      There are a couple of errors in your script.
      The first one is in the following line of code
      if(myAvg==null) myAvg = (ema (20) -ema (5));//replace the value with the parameter variable
      where you are calculating the equation only once ie the first time the efs is iterated (while the myAvg variable is null). To correct this you need to remove the null check and simply assign the equation to the variable myAvg
      The second error is in the following line of code
      return myAvg.getValue(0);
      where you are using the getValue() method of the series object. The variable myAvg is not a series but a value hence the use of the getValue() method is invalid in this case. Just return the variable myAvg
      Alex


      Originally posted by global
      I used to following code to create the first efsExternal which could be used in the second efs
      function preMain(){
      setPriceStudy(false);
      setStudyTitle("Fast EMA20-EMA5");
      setCursorLabelName("EMA");

      var fp1 = new FunctionParameter("Series", FunctionParameter);
      fp1.setName("EMA1 - EMA2");
      fp1.setLowerLimit(1);
      fp1.setUpperLimit(200);
      fp1.setDefault(20);
      }

      var myAvg = null;

      function main(Series){//add the parameter to the main definition

      if(myAvg==null) myAvg = (ema (20) -ema (5));//replace the value with the parameter variable

      return myAvg.getValue(0);
      }

      /////////////////////////////////////////////////////////////////////////


      The following is the code that I used to call on the efsExternal
      setCursorLabelName("Fast TA");

      var fp1 = new FunctionParameter("Length", FunctionParameter);
      fp1.setName("Length of %R");
      fp1.setLowerLimit(1);
      fp1.setUpperLimit(200);
      fp1.setDefault(20);
      }

      var myAvg = null;
      var ext = null

      function main(Length){//add the parameter to the main definition

      ext=efsExternal ("Step1Ext.efs")


      if(myAvg==null) myAvg = percentR((Length),ext);//replace the value with the parameter variable

      return myAvg.getValue(0);
      }

      Comment


      • #18
        Still not getting this right

        Thanks for your help. I made the corrections to the code in the externalefs as follows: (no errors reported)
        function preMain(){
        setPriceStudy(false);
        setStudyTitle("Fast EMA20-EMA5");
        setCursorLabelName("EMA");

        var fp1 = new FunctionParameter("Series", FunctionParameter);
        fp1.setName("EMA1 - EMA2");
        fp1.setLowerLimit(1);
        fp1.setUpperLimit(200);
        fp1.setDefault(20);
        }

        var myAvg = null;

        function main(Series){//add the parameter to the main definition

        myAvg = (ema (20) -ema (5));//replace the value with the parameter variable

        return myAvg;
        }
        //////////////////////////////
        When I plug it into the following efs - I don't get the required output: (obviously some code errors)

        setCursorLabelName("Fast TA");

        var fp1 = new FunctionParameter("Length", FunctionParameter);
        fp1.setName("Length of %R");
        fp1.setLowerLimit(1);
        fp1.setUpperLimit(200);
        fp1.setDefault(20);
        }

        var myAvg = null;
        var ext = null

        function main(Length){//add the parameter to the main definition

        ext=efsExternal ("Step1AExt.efs")


        if(myAvg==null) myAvg = percentR((Length),ext);//replace the value with the parameter variable

        return myAvg.getValue(0);
        }

        Comment


        • #19
          efsInternal - error

          I thought that by using the efsInternal - that I could save a step - but I seem to have made a code error someplace.

          function preMain(){
          setPriceStudy(false);
          setStudyTitle("FAST Fast %R 10 of EMA");
          setCursorLabelName("Fast%R");

          var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
          fp1.setName("Length of %R");
          fp1.setLowerLimit(1);
          fp1.setUpperLimit(200);
          fp1.setDefault(10);
          }


          var myAvg = null;
          var myvar = null

          function Strength () { return (ema (20) - ema (5));
          }

          function main(Length){//add the parameter to the main definition
          var myVar = efsInternal ("Strength");
          debugPrintln ("myVar")
          if(myAvg==null) myAvg = percentR((Length),myVar);//replace the value with the parameter variable
          debugPrintln ("myAvg")
          return myAvg.getValue(0);
          }

          Comment


          • #20
            Re: Still not getting this right

            global
            The first thing you need to do is to correct the incomplete syntax in the FunctionParameter items where you are missing the parameter type. For the description and syntax of the FunctionParameter Object see this article in the EFS KnowledgeBase
            As to the percentR() function it appears that for some reason it is not recognizing as a series the series object created by the efsExternal() call
            As a workaround you can enclose in a getSeries() call the ext variable used as the source in the percentR() function eg
            percentR((Length),getSeries(ext));
            Once you make this change the formula should work
            Alex


            Originally posted by global
            Thanks for your help. I made the corrections to the code in the externalefs as follows: (no errors reported)
            function preMain(){
            setPriceStudy(false);
            setStudyTitle("Fast EMA20-EMA5");
            setCursorLabelName("EMA");

            var fp1 = new FunctionParameter("Series", FunctionParameter);
            fp1.setName("EMA1 - EMA2");
            fp1.setLowerLimit(1);
            fp1.setUpperLimit(200);
            fp1.setDefault(20);
            }

            var myAvg = null;

            function main(Series){//add the parameter to the main definition

            myAvg = (ema (20) -ema (5));//replace the value with the parameter variable

            return myAvg;
            }
            //////////////////////////////
            When I plug it into the following efs - I don't get the required output: (obviously some code errors)

            setCursorLabelName("Fast TA");

            var fp1 = new FunctionParameter("Length", FunctionParameter);
            fp1.setName("Length of %R");
            fp1.setLowerLimit(1);
            fp1.setUpperLimit(200);
            fp1.setDefault(20);
            }

            var myAvg = null;
            var ext = null

            function main(Length){//add the parameter to the main definition

            ext=efsExternal ("Step1AExt.efs")


            if(myAvg==null) myAvg = percentR((Length),ext);//replace the value with the parameter variable

            return myAvg.getValue(0);
            }

            Comment

            Working...
            X