Announcement

Collapse
No announcement yet.

Help request for merging two studies

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

  • Help request for merging two studies

    Could someone please help me merge the following two studies while retaining their individual functionalities?

    I need the range value of of the first study to be used as the "Points" parameter of the second study. (Obviously the "Points" parameter would be fixed but all the other parameters of both studies could still be changed by the user)

    1st----------------------------------------------

    function preMain() {
    setPriceStudy(false);
    setStudyTitle("HL Range");
    setCursorLabelName("HL Range");
    }

    var aRange = null;

    function main(MALength) {
    if (MALength == null) MALength = 1;

    var vRange = high()-low();

    if (aRange == null) {
    aRange = new Array(MALength);
    }

    if (getBarState() == BARSTATE_NEWBAR) {
    aRange.pop();
    aRange.unshift(vRange);
    } else {
    aRange[0] = vRange;

    }

    if (aRange[MALength-1] == null) return;

    var nSum = 0;
    for (i = 0; i < MALength; ++i) {
    nSum += aRange[i];
    }

    var vMARange = nSum/MALength;

    return vMARange;
    }


    2nd--------------------------------------------------

    var vMA = null;
    vUpper = null;
    vLower = null;

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("MAChannel");
    setCursorLabelName("Short", 0);
    setCursorLabelName("MA", 1);
    setCursorLabelName("Long", 2);
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarFgColor(Color.yellow, 1);
    setDefaultBarFgColor(Color.lime, 2);
    setPlotType(PLOTTYPE_LINE,0);
    setPlotType(PLOTTYPE_LINE,1);
    setPlotType(PLOTTYPE_LINE,2);
    setDefaultBarThickness(1,0);
    setDefaultBarThickness(1,1);
    setDefaultBarThickness(1,2);
    checkVersion(1,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/basicMA&Channel.efs"); //Comment this line out if modifying the code

    var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
    fp1.setLowerLimit(1);
    fp1.setDefault(1); //Edit this value to set a new default

    var fp2 = new FunctionParameter("Offset", FunctionParameter.NUMBER);
    fp2.setDefault(0); //Edit this value to set a new default

    var fp3 = new FunctionParameter("Source", FunctionParameter.STRING);
    fp3.setName("Source");
    fp3.addOption("Close");
    fp3.addOption("High");
    fp3.addOption("Low");
    fp3.addOption("Open");
    fp3.addOption("HL/2");
    fp3.addOption("HLC/3");
    fp3.addOption("OHLC/4");
    fp3.setDefault("HL/2"); //Edit this value to set a new default

    var fp4 = new FunctionParameter("Type", FunctionParameter.STRING);
    fp4.setName("Type");
    fp4.addOption("MAStudy.SIMPLE");
    fp4.addOption("MAStudy.EXPONENTIAL");
    fp4.addOption("MAStudy.WEIGHTED");
    fp4.addOption("MAStudy.VOLUMEWEIGHTED");
    fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default

    var fp5 = new FunctionParameter("Value", FunctionParameter.STRING);
    fp5.setName("Value");
    fp5.addOption("Points");
    fp5.addOption("Percent");
    fp5.setDefault("Points");

    var fp6 = new FunctionParameter("Points", FunctionParameter.NUMBER);
    fp6.setName("Points");
    fp6.setLowerLimit(-2);
    fp6.setDefault(.5);


    }

    function main(Length,Offset,Source,Type,Value,Points) {

    if (vMA == null) vMA = new MAStudy(Length, Offset, Source, eval(Type));

    /*****************************************
    Insert your code following this text block
    Use vMA.getValue(MAStudy.MA) for your code
    ******************************************/

    if(Value=="Points"){
    var vUpper = vMA.getValue(MAStudy.MA)+Points;
    var vLower = vMA.getValue(MAStudy.MA)-Points;
    }
    else if(Value == "Percent"){
    var vUpper = vMA.getValue(MAStudy.MA)*(1+(Points/100));
    var vLower = vMA.getValue(MAStudy.MA)*(1-(Points/100));
    }


    return new Array (vUpper,vMA.getValue(MAStudy.MA),vLower);
    }

  • #2
    Re: Help request for merging two studies

    Himalaya
    The easiest way to do accomplish what you want to do is to use the efsExternal() function [see the link to the related article in the EFS KnowledgeBase for the complete description and syntax] to call the first efs. This function will retrieve the values returned by the called efs [ie the first efs] which you can then use in the calling efs [ie the second efs].
    The first thing you would do is add in the main function of the second efs the following line of code
    PHP Code:
    var PointsEFS efsExternal("name_of_called_efs.efs"Length); 
    and place it just after the line where you intialize the vMA study [ie if(vMA == null) vMA = new MAStudy(Length,...)]
    Replace "name_of_called_efs.efs" with the actual file name of the efs you are calling. Also make sure that the two efs are in the same folder
    The above assumes that the length used in the first efs is the same as the one used in the second efs. If instead you want to be able to use a different length then the line of code needs to be as follows
    PHP Code:
    var PointsEFS efsExternal("name_of_called_efs.efs"RangeLength); 
    At that point you need to add to the preMain function of the second efs a new FunctionParameter called RangeLength which will be used to define the length used in the called efs
    PHP Code:
    var fp7 = new FunctionParameter("RangeLength"FunctionParameter.NUMBER);
    fp7.setLowerLimit(1); 
    fp7.setDefault(1); //Edit this value to set a new default 
    and add that parameter to the argument list of the main function ie
    PHP Code:
    function main(Length,Offset,Source,Type,Value,PointsRangeLength) { 
    Now in your second efs all you need to do is replace the variable Points with PointEFS.getValue(0) in the following lines of code that calculate the Upper and Lower bands of the channel
    PHP Code:
    var vUpper vMA.getValue(MAStudy.MA)+Points;
    var 
    vLower vMA.getValue(MAStudy.MA)-Points;
    //and
    var vUpper vMA.getValue(MAStudy.MA)*(1+(Points/100));
    var 
    vLower vMA.getValue(MAStudy.MA)*(1-(Points/100)); 
    Once you have implemented these steps [which are essentially a copy and paste job] the second efs will be using the values returned by the first efs to calculate the bands
    If you encounter any problems post the second efs as you have modified it and I or someone else will be able to assist you further
    Alex


    Originally posted by Himalaya
    Could someone please help me merge the following two studies while retaining their individual functionalities?

    I need the range value of of the first study to be used as the "Points" parameter of the second study. (Obviously the "Points" parameter would be fixed but all the other parameters of both studies could still be changed by the user)

    1st----------------------------------------------

    function preMain() {
    setPriceStudy(false);
    setStudyTitle("HL Range");
    setCursorLabelName("HL Range");
    }

    var aRange = null;

    function main(MALength) {
    if (MALength == null) MALength = 1;

    var vRange = high()-low();

    if (aRange == null) {
    aRange = new Array(MALength);
    }

    if (getBarState() == BARSTATE_NEWBAR) {
    aRange.pop();
    aRange.unshift(vRange);
    } else {
    aRange[0] = vRange;

    }

    if (aRange[MALength-1] == null) return;

    var nSum = 0;
    for (i = 0; i < MALength; ++i) {
    nSum += aRange[i];
    }

    var vMARange = nSum/MALength;

    return vMARange;
    }


    2nd--------------------------------------------------

    var vMA = null;
    vUpper = null;
    vLower = null;

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("MAChannel");
    setCursorLabelName("Short", 0);
    setCursorLabelName("MA", 1);
    setCursorLabelName("Long", 2);
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarFgColor(Color.yellow, 1);
    setDefaultBarFgColor(Color.lime, 2);
    setPlotType(PLOTTYPE_LINE,0);
    setPlotType(PLOTTYPE_LINE,1);
    setPlotType(PLOTTYPE_LINE,2);
    setDefaultBarThickness(1,0);
    setDefaultBarThickness(1,1);
    setDefaultBarThickness(1,2);
    checkVersion(1,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/basicMA&Channel.efs"); //Comment this line out if modifying the code

    var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
    fp1.setLowerLimit(1);
    fp1.setDefault(1); //Edit this value to set a new default

    var fp2 = new FunctionParameter("Offset", FunctionParameter.NUMBER);
    fp2.setDefault(0); //Edit this value to set a new default

    var fp3 = new FunctionParameter("Source", FunctionParameter.STRING);
    fp3.setName("Source");
    fp3.addOption("Close");
    fp3.addOption("High");
    fp3.addOption("Low");
    fp3.addOption("Open");
    fp3.addOption("HL/2");
    fp3.addOption("HLC/3");
    fp3.addOption("OHLC/4");
    fp3.setDefault("HL/2"); //Edit this value to set a new default

    var fp4 = new FunctionParameter("Type", FunctionParameter.STRING);
    fp4.setName("Type");
    fp4.addOption("MAStudy.SIMPLE");
    fp4.addOption("MAStudy.EXPONENTIAL");
    fp4.addOption("MAStudy.WEIGHTED");
    fp4.addOption("MAStudy.VOLUMEWEIGHTED");
    fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default

    var fp5 = new FunctionParameter("Value", FunctionParameter.STRING);
    fp5.setName("Value");
    fp5.addOption("Points");
    fp5.addOption("Percent");
    fp5.setDefault("Points");

    var fp6 = new FunctionParameter("Points", FunctionParameter.NUMBER);
    fp6.setName("Points");
    fp6.setLowerLimit(-2);
    fp6.setDefault(.5);


    }

    function main(Length,Offset,Source,Type,Value,Points) {

    if (vMA == null) vMA = new MAStudy(Length, Offset, Source, eval(Type));

    /*****************************************
    Insert your code following this text block
    Use vMA.getValue(MAStudy.MA) for your code
    ******************************************/

    if(Value=="Points"){
    var vUpper = vMA.getValue(MAStudy.MA)+Points;
    var vLower = vMA.getValue(MAStudy.MA)-Points;
    }
    else if(Value == "Percent"){
    var vUpper = vMA.getValue(MAStudy.MA)*(1+(Points/100));
    var vLower = vMA.getValue(MAStudy.MA)*(1-(Points/100));
    }


    return new Array (vUpper,vMA.getValue(MAStudy.MA),vLower);
    }

    Comment


    • #3
      Merging EFS

      Alex,

      Thanks for the EFS instructions. Unfortunately I am too stupid to figure out how to implement the last one. I could not figure out what needed to be changed;

      "Now in your second efs all you need to do is replace the variable Points with PointEFS.getValue(0) in the following lines of code
      that calculate the Upper and Lower bands of the channel"


      var vUpper = vMA.getValue(MAStudy.MA)+Points;var vLower = vMA.getValue(MAStudy.MA)-Points;//andvar vUpper = vMA.getValue(MAStudy.MA)*(1+(Points/100));var vLower = vMA.getValue(MAStudy.MA)*(1-(Points/100));




      Here is what I was able to do so far by following your instructions;

      PHP Code:
      /*********************************************************
      Alexis C. Montenegro © July 2003                          
      Use and/or modify this code freely. If you redistribute it
      please include this and/or any other comment blocks and a 
      description of any changes you make.                      
      **********************************************************/

      var vMA null;
      vUpper null;
      vLower null;

      function 
      preMain() {
          
      setPriceStudy(true);
          
      setStudyTitle("PointsChannel");
          
      setCursorLabelName("Short"0);
          
      setCursorLabelName("MA"1);
          
      setCursorLabelName("Long"2);
          
      setDefaultBarFgColor(Color.red0);    
          
      setDefaultBarFgColor(Color.yellow1);
          
      setDefaultBarFgColor(Color.lime2);
          
      setPlotType(PLOTTYPE_LINE,0);
          
      setPlotType(PLOTTYPE_LINE,1);
          
      setPlotType(PLOTTYPE_LINE,2);
          
      setDefaultBarThickness(1,0);
          
      setDefaultBarThickness(1,1);
          
      setDefaultBarThickness(1,2);
          
      checkVersion(1,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/basicMA&Channel.efs"); //Comment this line out if modifying the code
              
          
      var fp1 = new FunctionParameter("Length"FunctionParameter.NUMBER);
          
      fp1.setLowerLimit(1);        
          
      fp1.setDefault(1); //Edit this value to set a new default
          
          
      var fp2 = new FunctionParameter("Offset"FunctionParameter.NUMBER);
          
      fp2.setDefault(0); //Edit this value to set a new default
          
          
      var fp3 = new FunctionParameter("Source"FunctionParameter.STRING);
          
      fp3.setName("Source");
          
      fp3.addOption("Close");
          
      fp3.addOption("High");
          
      fp3.addOption("Low");
          
      fp3.addOption("Open");
          
      fp3.addOption("HL/2");
          
      fp3.addOption("HLC/3");
          
      fp3.addOption("OHLC/4");
          
      fp3.setDefault("HL/2"); //Edit this value to set a new default    
          
          
      var fp4 = new FunctionParameter("Type"FunctionParameter.STRING);
          
      fp4.setName("Type");
          
      fp4.addOption("MAStudy.SIMPLE");
          
      fp4.addOption("MAStudy.EXPONENTIAL");
          
      fp4.addOption("MAStudy.WEIGHTED");
          
      fp4.addOption("MAStudy.VOLUMEWEIGHTED");
          
      fp4.setDefault("MAStudy.SIMPLE"); //Edit this value    to set a new default
          
          
      var fp5 = new FunctionParameter("Value"FunctionParameter.STRING);
          
      fp5.setName("Value");
          
      fp5.addOption("Points");
          
      fp5.addOption("Percent");
          
      fp5.setDefault("Points");
          
          var 
      fp6 = new FunctionParameter("Points"FunctionParameter.NUMBER);
          
      fp6.setName("Points");
          
      fp6.setLowerLimit(-2);
          
      fp6.setDefault(.5);
          
          var 
      fp7 = new FunctionParameter("RangeLength"FunctionParameter.NUMBER);

      fp7.setLowerLimit(1); 

      fp7.setDefault(3); //Edit this value to set a new default

      }

      function 
      main(Length,Offset,Source,Type,Value,PointsRangeLength) {
         
          if (
      vMA == nullvMA = new MAStudy(LengthOffsetSource, eval(Type));
          var 
      PointsEFS efsExternal("maofhlrange.efs"RangeLength);
       
      /*****************************************
      Insert your code following this text block
      Use vMA.getValue(MAStudy.MA) for your code
      ******************************************/
          
          
      if(Value=="Points"){
          var 
      vUpper vMA.getValue(MAStudy.MA)+Points;
          var 
      vLower vMA.getValue(MAStudy.MA)-Points;
          }
          else if(
      Value == "Percent"){
          var 
      vUpper vMA.getValue(MAStudy.MA)*(1+(Points/100));
          var 
      vLower vMA.getValue(MAStudy.MA)*(1-(Points/100));
          }
          
          
          return new Array (
      vUpper,vMA.getValue(MAStudy.MA),vLower);

      Comment


      • #4
        Re: Merging EFS

        Himalaya
        Just replace the following section of code in your script
        PHP Code:
        if(Value=="Points"){
            var 
        vUpper vMA.getValue(MAStudy.MA)+Points;
            var 
        vLower vMA.getValue(MAStudy.MA)-Points;
            }
            else if(
        Value == "Percent"){
            var 
        vUpper vMA.getValue(MAStudy.MA)*(1+(Points/100));
            var 
        vLower vMA.getValue(MAStudy.MA)*(1-(Points/100));
            } 
        with the following
        PHP Code:
        if(Value=="Points"){
            var 
        vUpper vMA.getValue(MAStudy.MA)+PointsEFS.getValue(0);
            var 
        vLower vMA.getValue(MAStudy.MA)-PointsEFS.getValue(0);
            }
            else if(
        Value == "Percent"){
            var 
        vUpper vMA.getValue(MAStudy.MA)*(1+(PointsEFS.getValue(0)/100));
            var 
        vLower vMA.getValue(MAStudy.MA)*(1-(PointsEFS.getValue(0)/100));
            } 
        As you can see all I did was replace the variable name Points with PointsEFS.getValue(0)
        Alex


        Originally posted by Himalaya
        Alex,

        Thanks for the EFS instructions. Unfortunately I am too stupid to figure out how to implement the last one. I could not figure out what needed to be changed;

        "Now in your second efs all you need to do is replace the variable Points with PointEFS.getValue(0) in the following lines of code
        that calculate the Upper and Lower bands of the channel"


        var vUpper = vMA.getValue(MAStudy.MA)+Points;var vLower = vMA.getValue(MAStudy.MA)-Points;//andvar vUpper = vMA.getValue(MAStudy.MA)*(1+(Points/100));var vLower = vMA.getValue(MAStudy.MA)*(1-(Points/100));




        Here is what I was able to do so far by following your instructions;

        PHP Code:
        /*********************************************************
        Alexis C. Montenegro © July 2003                          
        Use and/or modify this code freely. If you redistribute it
        please include this and/or any other comment blocks and a 
        description of any changes you make.                      
        **********************************************************/

        var vMA null;
        vUpper null;
        vLower null;

        function 
        preMain() {
            
        setPriceStudy(true);
            
        setStudyTitle("PointsChannel");
            
        setCursorLabelName("Short"0);
            
        setCursorLabelName("MA"1);
            
        setCursorLabelName("Long"2);
            
        setDefaultBarFgColor(Color.red0);    
            
        setDefaultBarFgColor(Color.yellow1);
            
        setDefaultBarFgColor(Color.lime2);
            
        setPlotType(PLOTTYPE_LINE,0);
            
        setPlotType(PLOTTYPE_LINE,1);
            
        setPlotType(PLOTTYPE_LINE,2);
            
        setDefaultBarThickness(1,0);
            
        setDefaultBarThickness(1,1);
            
        setDefaultBarThickness(1,2);
            
        checkVersion(1,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/basicMA&Channel.efs"); //Comment this line out if modifying the code
                
            
        var fp1 = new FunctionParameter("Length"FunctionParameter.NUMBER);
            
        fp1.setLowerLimit(1);        
            
        fp1.setDefault(1); //Edit this value to set a new default
            
            
        var fp2 = new FunctionParameter("Offset"FunctionParameter.NUMBER);
            
        fp2.setDefault(0); //Edit this value to set a new default
            
            
        var fp3 = new FunctionParameter("Source"FunctionParameter.STRING);
            
        fp3.setName("Source");
            
        fp3.addOption("Close");
            
        fp3.addOption("High");
            
        fp3.addOption("Low");
            
        fp3.addOption("Open");
            
        fp3.addOption("HL/2");
            
        fp3.addOption("HLC/3");
            
        fp3.addOption("OHLC/4");
            
        fp3.setDefault("HL/2"); //Edit this value to set a new default    
            
            
        var fp4 = new FunctionParameter("Type"FunctionParameter.STRING);
            
        fp4.setName("Type");
            
        fp4.addOption("MAStudy.SIMPLE");
            
        fp4.addOption("MAStudy.EXPONENTIAL");
            
        fp4.addOption("MAStudy.WEIGHTED");
            
        fp4.addOption("MAStudy.VOLUMEWEIGHTED");
            
        fp4.setDefault("MAStudy.SIMPLE"); //Edit this value    to set a new default
            
            
        var fp5 = new FunctionParameter("Value"FunctionParameter.STRING);
            
        fp5.setName("Value");
            
        fp5.addOption("Points");
            
        fp5.addOption("Percent");
            
        fp5.setDefault("Points");
            
            var 
        fp6 = new FunctionParameter("Points"FunctionParameter.NUMBER);
            
        fp6.setName("Points");
            
        fp6.setLowerLimit(-2);
            
        fp6.setDefault(.5);
            
            var 
        fp7 = new FunctionParameter("RangeLength"FunctionParameter.NUMBER);

        fp7.setLowerLimit(1); 

        fp7.setDefault(3); //Edit this value to set a new default

        }

        function 
        main(Length,Offset,Source,Type,Value,PointsRangeLength) {
           
            if (
        vMA == nullvMA = new MAStudy(LengthOffsetSource, eval(Type));
            var 
        PointsEFS efsExternal("maofhlrange.efs"RangeLength);
         
        /*****************************************
        Insert your code following this text block
        Use vMA.getValue(MAStudy.MA) for your code
        ******************************************/
            
            
        if(Value=="Points"){
            var 
        vUpper vMA.getValue(MAStudy.MA)+Points;
            var 
        vLower vMA.getValue(MAStudy.MA)-Points;
            }
            else if(
        Value == "Percent"){
            var 
        vUpper vMA.getValue(MAStudy.MA)*(1+(Points/100));
            var 
        vLower vMA.getValue(MAStudy.MA)*(1-(Points/100));
            }
            
            
            return new Array (
        vUpper,vMA.getValue(MAStudy.MA),vLower);

        Comment


        • #5
          Thanks

          Thanks again Alex

          Comment


          • #6
            Re: Thanks

            Himalaya
            You are most welcome
            Alex


            Originally posted by Himalaya
            Thanks again Alex

            Comment


            • #7
              Oops, one more adjustment

              How would I get the HL range to only be calculated from the previous (3) bars and not include the current bar as one of the three bars?

              I just realized that if the new/merged EFS includes the current bar in the Range calculation the channels/bands will re-adjust multiple times as the current bar is built. I would like to see them fixed for the duration of the current bar based on the three previous bar's Range.


              /************************************************** *******
              Alexis C. Montenegro © July 2003
              Use and/or modify this code freely. If you redistribute it
              please include this and/or any other comment blocks and a
              description of any changes you make.
              ************************************************** ********/

              var vMA = null;
              vUpper = null;
              vLower = null;

              function preMain() {
              setPriceStudy(true);
              setStudyTitle("PointsChannel");
              setCursorLabelName("Short", 0);
              setCursorLabelName("MA", 1);
              setCursorLabelName("Long", 2);
              setDefaultBarFgColor(Color.red, 0);
              setDefaultBarFgColor(Color.black, 1);
              setDefaultBarFgColor(Color.lime, 2);
              setPlotType(PLOTTYPE_LINE,0);
              setPlotType(PLOTTYPE_LINE,1);
              setPlotType(PLOTTYPE_LINE,2);
              setDefaultBarThickness(1,0);
              setDefaultBarThickness(1,1);
              setDefaultBarThickness(1,2);
              checkVersion(1,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/basicMA&Channel.efs"); //Comment this line out if modifying the code

              var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
              fp1.setLowerLimit(1);
              fp1.setDefault(1); //Edit this value to set a new default

              var fp2 = new FunctionParameter("Offset", FunctionParameter.NUMBER);
              fp2.setDefault(0); //Edit this value to set a new default

              var fp3 = new FunctionParameter("Source", FunctionParameter.STRING);
              fp3.setName("Source");
              fp3.addOption("Close");
              fp3.addOption("High");
              fp3.addOption("Low");
              fp3.addOption("Open");
              fp3.addOption("HL/2");
              fp3.addOption("HLC/3");
              fp3.addOption("OHLC/4");
              fp3.setDefault("HL/2"); //Edit this value to set a new default

              var fp4 = new FunctionParameter("Type", FunctionParameter.STRING);
              fp4.setName("Type");
              fp4.addOption("MAStudy.SIMPLE");
              fp4.addOption("MAStudy.EXPONENTIAL");
              fp4.addOption("MAStudy.WEIGHTED");
              fp4.addOption("MAStudy.VOLUMEWEIGHTED");
              fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default

              var fp5 = new FunctionParameter("Value", FunctionParameter.STRING);
              fp5.setName("Value");
              fp5.addOption("Points");
              fp5.addOption("Percent");
              fp5.setDefault("Points");

              var fp6 = new FunctionParameter("Points", FunctionParameter.NUMBER);
              fp6.setName("Points");
              fp6.setLowerLimit(-2);
              fp6.setDefault(.5);

              var fp7 = new FunctionParameter("RangeLength", FunctionParameter.NUMBER);

              fp7.setLowerLimit(1);

              fp7.setDefault(3); //Edit this value to set a new default

              }

              function main(Length,Offset,Source,Type,Value,Points,RangeL ength) {

              if (vMA == null) vMA = new MAStudy(Length, Offset, Source, eval(Type));
              var PointsEFS = efsExternal("maofhlrange.efs", RangeLength);

              /*****************************************
              Insert your code following this text block
              Use vMA.getValue(MAStudy.MA) for your code
              ******************************************/

              if(Value=="Points"){

              var vUpper = vMA.getValue(MAStudy.MA)+PointsEFS.getValue(0);

              var vLower = vMA.getValue(MAStudy.MA)-PointsEFS.getValue(0);

              }

              else if(Value == "Percent"){

              var vUpper = vMA.getValue(MAStudy.MA)*(1+(PointsEFS.getValue(0)/100));

              var vLower = vMA.getValue(MAStudy.MA)*(1-(PointsEFS.getValue(0)/100));

              }


              return new Array (vUpper,vMA.getValue(MAStudy.MA),vLower);
              }

              Comment


              • #8
                Re: Oops, one more adjustment

                Himalaya
                Replace each instance of PivotEFS.getValue(0) which retrieves the current value of the range with PivotsEFS.getValue(-1) which retrieves the previous value of the range
                Alex


                Originally posted by Himalaya
                How would I get the HL range to only be calculated from the previous (3) bars and not include the current bar as one of the three bars?

                I just realized that if the new/merged EFS includes the current bar in the Range calculation the channels/bands will re-adjust multiple times as the current bar is built. I would like to see them fixed for the duration of the current bar based on the three previous bar's Range.


                /************************************************** *******
                Alexis C. Montenegro © July 2003
                Use and/or modify this code freely. If you redistribute it
                please include this and/or any other comment blocks and a
                description of any changes you make.
                ************************************************** ********/

                var vMA = null;
                vUpper = null;
                vLower = null;

                function preMain() {
                setPriceStudy(true);
                setStudyTitle("PointsChannel");
                setCursorLabelName("Short", 0);
                setCursorLabelName("MA", 1);
                setCursorLabelName("Long", 2);
                setDefaultBarFgColor(Color.red, 0);
                setDefaultBarFgColor(Color.black, 1);
                setDefaultBarFgColor(Color.lime, 2);
                setPlotType(PLOTTYPE_LINE,0);
                setPlotType(PLOTTYPE_LINE,1);
                setPlotType(PLOTTYPE_LINE,2);
                setDefaultBarThickness(1,0);
                setDefaultBarThickness(1,1);
                setDefaultBarThickness(1,2);
                checkVersion(1,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/basicMA&Channel.efs"); //Comment this line out if modifying the code

                var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
                fp1.setLowerLimit(1);
                fp1.setDefault(1); //Edit this value to set a new default

                var fp2 = new FunctionParameter("Offset", FunctionParameter.NUMBER);
                fp2.setDefault(0); //Edit this value to set a new default

                var fp3 = new FunctionParameter("Source", FunctionParameter.STRING);
                fp3.setName("Source");
                fp3.addOption("Close");
                fp3.addOption("High");
                fp3.addOption("Low");
                fp3.addOption("Open");
                fp3.addOption("HL/2");
                fp3.addOption("HLC/3");
                fp3.addOption("OHLC/4");
                fp3.setDefault("HL/2"); //Edit this value to set a new default

                var fp4 = new FunctionParameter("Type", FunctionParameter.STRING);
                fp4.setName("Type");
                fp4.addOption("MAStudy.SIMPLE");
                fp4.addOption("MAStudy.EXPONENTIAL");
                fp4.addOption("MAStudy.WEIGHTED");
                fp4.addOption("MAStudy.VOLUMEWEIGHTED");
                fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default

                var fp5 = new FunctionParameter("Value", FunctionParameter.STRING);
                fp5.setName("Value");
                fp5.addOption("Points");
                fp5.addOption("Percent");
                fp5.setDefault("Points");

                var fp6 = new FunctionParameter("Points", FunctionParameter.NUMBER);
                fp6.setName("Points");
                fp6.setLowerLimit(-2);
                fp6.setDefault(.5);

                var fp7 = new FunctionParameter("RangeLength", FunctionParameter.NUMBER);

                fp7.setLowerLimit(1);

                fp7.setDefault(3); //Edit this value to set a new default

                }

                function main(Length,Offset,Source,Type,Value,Points,RangeL ength) {

                if (vMA == null) vMA = new MAStudy(Length, Offset, Source, eval(Type));
                var PointsEFS = efsExternal("maofhlrange.efs", RangeLength);

                /*****************************************
                Insert your code following this text block
                Use vMA.getValue(MAStudy.MA) for your code
                ******************************************/

                if(Value=="Points"){

                var vUpper = vMA.getValue(MAStudy.MA)+PointsEFS.getValue(0);

                var vLower = vMA.getValue(MAStudy.MA)-PointsEFS.getValue(0);

                }

                else if(Value == "Percent"){

                var vUpper = vMA.getValue(MAStudy.MA)*(1+(PointsEFS.getValue(0)/100));

                var vLower = vMA.getValue(MAStudy.MA)*(1-(PointsEFS.getValue(0)/100));

                }


                return new Array (vUpper,vMA.getValue(MAStudy.MA),vLower);
                }

                Comment


                • #9
                  That was it, Thanks again! (no message)

                  Thanks

                  Comment

                  Working...
                  X