Announcement

Collapse
No announcement yet.

Cannot call previous level

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

  • Cannot call previous level

    I am trying to create a set of bands that allow me to define a range. I have created a starting point that draws a midband at the middle of the previous bar. What I want to do is draw the band at the same level until the high of the current bar exceeds that level by a certain number of ticks and then the midband will trail the high by that number of ticks, and vice versa for the low.

    I am drawing the midband with a function I called calcMB. My challenge has come trying to determine what the value of the midband was on the previous bar. I have tried to call calcMB(-1), MidBand(-1), RangeBands(-1) etc but none of those work. I must be missing something stupid. Any help is appreciated.

    There is probably a way to put my code in a box but I could not figure it out.

    Thanks,

    Murray


    var MidBand;
    var aRange = new Array();

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("RangeBands");
    setShowTitleParameters(false);
    setPlotType(PLOTTYPE_LINE, 0);

    setCursorLabelName("MidBand", 0); //MidBand
    setCursorLabelName("UpperBand", 1); //UpperBand
    setCursorLabelName("LowerBand", 2); //LowerBand

    setDefaultBarFgColor(Color.RGB(255,0,0), 0); // MidBand
    setDefaultBarFgColor(Color.RGB(0,255,0), 1); // UpperBand
    setDefaultBarFgColor(Color.RGB(0,255,0), 2); // LowerBand

    setDefaultBarStyle(PS_SOLID,0); // MidBand
    setDefaultBarStyle(PS_SOLID,1); // UpperBand
    setDefaultBarStyle(PS_SOLID,2); // LowerBand

    var colBGColor = new FunctionParameter("cColor", FunctionParameter.COLOR);
    colBGColor.setName("Range Color")
    colBGColor.setDefault(Color.yellow);

    var x = 0;
    aRange[x] = new FunctionParameter("Range", FunctionParameter.NUMBER);
    with(aRange[x++]) {
    setLowerLimit(1);
    setDefault(10);
    }
    }

    function main(Range,cColor) {

    var nDisp = getMinTick() * Range;
    MidBand = efsInternal("calcMB");
    var UpperBand = MidBand + nDisp
    var LowerBand = MidBand - nDisp
    setBarBgColor(cColor,0,UpperBand,LowerBand);

    return new Array(MidBand, UpperBand, LowerBand);
    }

    function calcMB() {

    var nMid = (high(-1) + low(-1))/2;
    /* if (high() - nDisp) > (MidBand(-1) {
    nMid = (high() - nDisp);
    }
    if (high() > high(-1)) {
    nMid = high() - nDisp;
    }
    */

    return nMid;
    }

  • #2
    CPOMorty
    To call the value of a series object [which is what you created using the efsInternal() function] you use the getValue() method of the Series Object (see this article in the EFS KnowledgeBase) hence Midband.getValue(-1)
    As to placing your code in "boxes" use the [PHP] or [CODE] tags (see the Forum FAQ for more information)
    Alex


    Originally posted by CPOMorty View Post
    I am trying to create a set of bands that allow me to define a range. I have created a starting point that draws a midband at the middle of the previous bar. What I want to do is draw the band at the same level until the high of the current bar exceeds that level by a certain number of ticks and then the midband will trail the high by that number of ticks, and vice versa for the low.

    I am drawing the midband with a function I called calcMB. My challenge has come trying to determine what the value of the midband was on the previous bar. I have tried to call calcMB(-1), MidBand(-1), RangeBands(-1) etc but none of those work. I must be missing something stupid. Any help is appreciated.

    There is probably a way to put my code in a box but I could not figure it out.

    Thanks,

    Murray


    var MidBand;
    var aRange = new Array();

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("RangeBands");
    setShowTitleParameters(false);
    setPlotType(PLOTTYPE_LINE, 0);

    setCursorLabelName("MidBand", 0); //MidBand
    setCursorLabelName("UpperBand", 1); //UpperBand
    setCursorLabelName("LowerBand", 2); //LowerBand

    setDefaultBarFgColor(Color.RGB(255,0,0), 0); // MidBand
    setDefaultBarFgColor(Color.RGB(0,255,0), 1); // UpperBand
    setDefaultBarFgColor(Color.RGB(0,255,0), 2); // LowerBand

    setDefaultBarStyle(PS_SOLID,0); // MidBand
    setDefaultBarStyle(PS_SOLID,1); // UpperBand
    setDefaultBarStyle(PS_SOLID,2); // LowerBand

    var colBGColor = new FunctionParameter("cColor", FunctionParameter.COLOR);
    colBGColor.setName("Range Color")
    colBGColor.setDefault(Color.yellow);

    var x = 0;
    aRange[x] = new FunctionParameter("Range", FunctionParameter.NUMBER);
    with(aRange[x++]) {
    setLowerLimit(1);
    setDefault(10);
    }
    }

    function main(Range,cColor) {

    var nDisp = getMinTick() * Range;
    MidBand = efsInternal("calcMB");
    var UpperBand = MidBand + nDisp
    var LowerBand = MidBand - nDisp
    setBarBgColor(cColor,0,UpperBand,LowerBand);

    return new Array(MidBand, UpperBand, LowerBand);
    }

    function calcMB() {

    var nMid = (high(-1) + low(-1))/2;
    /* if (high() - nDisp) > (MidBand(-1) {
    nMid = (high() - nDisp);
    }
    if (high() > high(-1)) {
    nMid = high() - nDisp;
    }
    */

    return nMid;
    }

    Comment


    • #3
      Thanks Alex,

      I tried using this in the calcMB function as below and I get an Open Formula Output, the same as my original code gave me. I also tried the same line in the main function planning to pass the value to the calcMB function but there I get a syntax error that MidBand is not defined even though it is declared as a global variable.

      Murray


      function calcMB() {

      var nMidLast = MidBand.getValue(-1);
      var nMid = (high(-1) + low(-1))/2;

      return nMid;
      }

      Comment


      • #4
        Murray
        You cannot pass back to the external function a value that you retrieved from the series you created by calling that same function through esfInternal().
        You need to first do your calculations in the external function and if within that function you need a prior value of a variable that is not a series object then you have to retrieve it in a different way and there are several at your disposal. See this thread for examples on how to do this. Also search the forum and you will find numerous other threads on this topic as it has been discussed before
        Alex


        Originally posted by CPOMorty View Post
        Thanks Alex,

        I tried using this in the calcMB function as below and I get an Open Formula Output, the same as my original code gave me. I also tried the same line in the main function planning to pass the value to the calcMB function but there I get a syntax error that MidBand is not defined even though it is declared as a global variable.

        Murray


        function calcMB() {

        var nMidLast = MidBand.getValue(-1);
        var nMid = (high(-1) + low(-1))/2;

        return nMid;
        }

        Comment


        • #5
          Hi Alex,

          I am using Firefox and Windows 10. Every search I try comes back blank. Is there a secret to using search that I have not found?

          Murray

          Comment


          • #6
            Murray
            Use Google (with any browser) to search within the forum eg "previous value" site:forum.esignal.com
            That said I have no problems using vBulletin's own forum search in IE11 or Edge
            Alex


            Originally posted by CPOMorty View Post
            Hi Alex,

            I am using Firefox and Windows 10. Every search I try comes back blank. Is there a secret to using search that I have not found?

            Murray

            Comment


            • #7
              Thanks!

              Murray

              Comment


              • #8
                Murray
                You are welcome
                Alex


                Originally posted by CPOMorty View Post
                Thanks!

                Murray

                Comment


                • #9
                  So I have spent over 2 weeks with 0 progress on this issue. The answers here are cryptic to me. I have printed and read through the EFS guides and read many posts that all seem to be the same without clear answers. I understand that eSignal doesn't support EFS with working code examples any more, but is there anyone who has actually made this work who can share their code with me so I can use it as an example? All I find is pieces that all look fragmented to me. A working indicator that reads its own previous values would be very helpful in my learning how to do this. Are there any indicators posted that I could download and learn from?

                  Thanks.

                  Comment


                  • #10
                    CPOMorty
                    Enclosed below are three basic examples of a script that references its own previous value (note that the script in and of itself serves no purpose other than just being an example)
                    The first one uses the ref() function (see the EFS KnowledgeBase for more information), the second transfers the values from one variable to another [both of which need to be global] at the first tick of each new bar simply to store its previous value and the third uses an array (again see the EFS KnowledgeBase for more information).
                    As I said I have explained in several other threads the purpose of each method including limitations (if any) and the reasons for choosing one over another
                    As to their usage there are literally hundreds of formulas posted in the library or in this forum that will use any of them at some point
                    Alex







                    Originally posted by CPOMorty View Post
                    So I have spent over 2 weeks with 0 progress on this issue. The answers here are cryptic to me. I have printed and read through the EFS guides and read many posts that all seem to be the same without clear answers. I understand that eSignal doesn't support EFS with working code examples any more, but is there anyone who has actually made this work who can share their code with me so I can use it as an example? All I find is pieces that all look fragmented to me. A working indicator that reads its own previous values would be very helpful in my learning how to do this. Are there any indicators posted that I could download and learn from?

                    Thanks.

                    Comment


                    • #11
                      Working Code

                      Thanks Alex,

                      That was very helpful. I now have a working piece of code. For those following my code is below, simple once the nuances are known:

                      PHP Code:
                      var MidBand null;
                      var 
                      nMidLast null;
                      var 
                      aRange = new Array();
                      var 
                      MyVar 0;

                      function 
                      preMain() {
                          
                      setPriceStudy(true);
                          
                      setStudyTitle("RangeBands");
                          
                      setShowTitleParameters(false);
                          
                      setPlotType(PLOTTYPE_LINE0);
                          
                          
                      setCursorLabelName("MidBand"0); //MidBand
                          
                      setCursorLabelName("UpperBand"1); //UpperBand
                          
                      setCursorLabelName("LowerBand"2); //LowerBand
                          
                          
                      setDefaultBarFgColor(Color.RGB(255,0,0), 0); // MidBand
                          
                      setDefaultBarFgColor(Color.RGB(0,255,0), 1);  // UpperBand
                          
                      setDefaultBarFgColor(Color.RGB(0,255,0), 2);  // LowerBand
                          
                          
                      setDefaultBarStyle(PS_SOLID,0); // MidBand
                          
                      setDefaultBarStyle(PS_SOLID,1); // UpperBand
                          
                      setDefaultBarStyle(PS_SOLID,2); // LowerBand

                      var colBGColor = new FunctionParameter("cColor"FunctionParameter.COLOR);
                          
                      colBGColor.setName("Range Color")
                          
                      colBGColor.setDefault(Color.yellow);
                          
                      var 
                      0;
                          
                      aRange[x] = new FunctionParameter("Range"FunctionParameter.NUMBER);
                          
                      with(aRange[x++]) {
                              
                      setLowerLimit(1);
                              
                      setDefault(10);
                          }
                      }

                      function 
                      main(Range,cColor) {
                          
                          if(
                      getCurrentBarCount()<2)
                              
                      MidBand=(high()+low())/2;
                          if(
                      getBarState()==BARSTATE_NEWBAR)
                              
                      nMidLast=MidBand;
                          
                          var 
                      nDisp getMinTick() * Range;

                          if (
                      nMidLast < (high()-nDisp))
                              
                      MidBand = (high() - nDisp);
                          else if (
                      nMidLast > (low() + nDisp))
                              
                      MidBand = (low() + nDisp);


                          var 
                      UpperBand MidBand nDisp;
                          var 
                      LowerBand MidBand nDisp;
                          
                      setBarBgColor(cColor,0,UpperBand,LowerBand);

                          return new Array(
                      MidBandUpperBandLowerBand);

                      Comment


                      • #12
                        CPOMorty
                        You are welcome
                        Alex


                        Originally posted by CPOMorty View Post
                        Thanks Alex,

                        That was very helpful. I now have a working piece of code. For those following my code is below, simple once the nuances are known:

                        PHP Code:
                        var MidBand null;
                        var 
                        nMidLast null;
                        var 
                        aRange = new Array();
                        var 
                        MyVar 0;

                        function 
                        preMain() {
                            
                        setPriceStudy(true);
                            
                        setStudyTitle("RangeBands");
                            
                        setShowTitleParameters(false);
                            
                        setPlotType(PLOTTYPE_LINE0);
                            
                            
                        setCursorLabelName("MidBand"0); //MidBand
                            
                        setCursorLabelName("UpperBand"1); //UpperBand
                            
                        setCursorLabelName("LowerBand"2); //LowerBand
                            
                            
                        setDefaultBarFgColor(Color.RGB(255,0,0), 0); // MidBand
                            
                        setDefaultBarFgColor(Color.RGB(0,255,0), 1);  // UpperBand
                            
                        setDefaultBarFgColor(Color.RGB(0,255,0), 2);  // LowerBand
                            
                            
                        setDefaultBarStyle(PS_SOLID,0); // MidBand
                            
                        setDefaultBarStyle(PS_SOLID,1); // UpperBand
                            
                        setDefaultBarStyle(PS_SOLID,2); // LowerBand

                        var colBGColor = new FunctionParameter("cColor"FunctionParameter.COLOR);
                            
                        colBGColor.setName("Range Color")
                            
                        colBGColor.setDefault(Color.yellow);
                            
                        var 
                        0;
                            
                        aRange[x] = new FunctionParameter("Range"FunctionParameter.NUMBER);
                            
                        with(aRange[x++]) {
                                
                        setLowerLimit(1);
                                
                        setDefault(10);
                            }
                        }

                        function 
                        main(Range,cColor) {
                            
                            if(
                        getCurrentBarCount()<2)
                                
                        MidBand=(high()+low())/2;
                            if(
                        getBarState()==BARSTATE_NEWBAR)
                                
                        nMidLast=MidBand;
                            
                            var 
                        nDisp getMinTick() * Range;

                            if (
                        nMidLast < (high()-nDisp))
                                
                        MidBand = (high() - nDisp);
                            else if (
                        nMidLast > (low() + nDisp))
                                
                        MidBand = (low() + nDisp);


                            var 
                        UpperBand MidBand nDisp;
                            var 
                        LowerBand MidBand nDisp;
                            
                        setBarBgColor(cColor,0,UpperBand,LowerBand);

                            return new Array(
                        MidBandUpperBandLowerBand);

                        Comment

                        Working...
                        X