Announcement

Collapse
No announcement yet.

2% band over 10day Simple MA ?

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

  • 2% band over 10day Simple MA ?

    Can anyone suggest an easy way to get this coded quickly ?

  • #2
    sgarbs
    The Formula Wizard. Attached is the efs created with the FW.
    Alex
    Attached Files

    Comment


    • #3
      Thanks alex

      Many thanks. I just downloaded it and truly appreciate your efforts. Maybe ill get off my feet and figure out how to use the wizard effectively.

      Comment


      • #4
        PHP Code:
        Length 10;
        var 
        avg = new MAStudy(Length0"Close"MAStudy.SIMPLE);

        function 
        preMain() {
            
        setPriceStudy(true);
            
        setCursorLabelName("top"0);
            
        setCursorLabelName("sma"1);
            
        setCursorLabelName("bottom"2);
            
        setDefaultBarFgColor(Color.red0);
            
        setDefaultBarFgColor(Color.blue1);
            
        setDefaultBarFgColor(Color.green2);
        }

        function 
        main(LengthPercent) {
            if (
        Length == nullLength 10;
            if (
        Percent == nullPercent 2;
            
            var 
        sma avg.getValue(MAStudy.MA);
            var 
        top sma * (Percent .01);
            var 
        bottom sma * (Percent .01);
            
            return new Array(
        topsmabottom);

        Attached Files

        Comment


        • #5
          xygeek...

          Thanks for helping with that. My question is: If i try to emulate this formula by using the efs wizard - i cant figure out where i would tell it to increase the the 10day ma by 1+2% ?

          I only see how to place the 10 day MA , but not add a new 2% band ?

          Can this only be done by actually writing the sript ?

          Comment


          • #6
            sgarbs
            In the Formula Wizard use the EnvelopeStudy not the MAStudy.
            Alex
            Last edited by ACM; 06-13-2003, 02:05 PM.

            Comment


            • #7
              xygeek
              The way your formula is laid out does not allow for inputs to be passed on to the built-in MA Study. In fact you cannot change the length of the MA via Edit Studies.
              You need to modify the formula as follows if you want to be able to use Edit Studies to change the MA Length
              Alex

              PHP Code:
              function preMain() {
                  
              setPriceStudy(true);
                  
              setCursorLabelName("top"0);
                  
              setCursorLabelName("sma"1);
                  
              setCursorLabelName("bottom"2);
                  
              setDefaultBarFgColor(Color.red0);
                  
              setDefaultBarFgColor(Color.blue1);
                  
              setDefaultBarFgColor(Color.green2);
              }

              function 
              main(LengthPercent) {
                  if (
              Length == nullLength 10;
                  if (
              Percent == nullPercent 2;
                  
                  var 
              avg = new MAStudy(Length0"Close"MAStudy.SIMPLE);
                  
                  var 
              sma avg.getValue(MAStudy.MA);
                  var 
              top sma * (Percent .01);
                  var 
              bottom sma * (Percent .01);
                  
                  return new Array(
              topsmabottom);

              Comment


              • #8
                Thanks! I wasn't aware of that.

                Comment


                • #9
                  Might I suggest a few changes to Alex's code.

                  Make the var declaration for the builtin a local global by placing the statement outside of main(). Matt has suggested to me in the past that declaring it inside of main() could cause problems.

                  Also be sure to initialize it just once for any change in MA length. If it is initialized for every tick you might see crashes at times (I have seen this first hand).

                  So it would look like:

                  PHP Code:

                  var avg null;
                  var 
                  nOldLen 0;

                  function 
                  preMain() {
                      
                  setPriceStudy(true);
                      
                  setCursorLabelName("top"0);
                      
                  setCursorLabelName("sma"1);
                      
                  setCursorLabelName("bottom"2);
                      
                  setDefaultBarFgColor(Color.red0);
                      
                  setDefaultBarFgColor(Color.blue1);
                      
                  setDefaultBarFgColor(Color.green2);
                  }

                  function 
                  main(LengthPercent) {
                      if (
                  Length == nullLength 10;
                      if (
                  Percent == nullPercent 2;
                      
                      if (
                  nOldLen == || Length != nOldLen){
                          
                  avg = new MAStudy(Length0"Close"MAStudy.SIMPLE);
                          
                  nOldLen Length;
                     }
                      
                      var 
                  sma avg.getValue(MAStudy.MA);
                      var 
                  top sma * (Percent .01);
                      var 
                  bottom sma * (Percent .01);
                      
                      return new Array(
                  topsmabottom);

                  I believe that keeping the old value of Length and comparing it to
                  the current length is overkill for this specific example, as changing any of the values via edit study will force eSignal to interate all the bars. This means a simple test for:

                  if (avg == null)

                  Would be enough. But I coded it this way so that if people wanted to create an EFS that would allow the Length of the MA to modifed by the EFS dynamically, they would have a template.

                  Garth
                  Garth

                  Comment


                  • #10
                    Thanks, that makes sense. I appreciate the precise syntax you use to refer to things such as local globals. It's helping me understand javascript.

                    However the input parameters are inaccessible from the edit study menu again. I like the concept of dynamically updating parameters so please let me know if you get it sorted out.

                    Comment


                    • #11
                      They are accessible (and even work - just tested) here. If you made ANY changes to the code as posted (including adding comments) either post the changed version here and I will look at it, or remove the changes and see if it works.

                      G
                      Garth

                      Comment


                      • #12
                        Is it possible the lengthy comments made the inputs disappear? It works fine with the comments removed. Here’s the version that didn't work:

                        PHP Code:
                        /*  Might I suggest a few changes to Alex's code. 

                        Make the var declaration for the builtin a local global by placing the statement outside of main(). 
                        Matt has suggested to me in the past that declaring it inside of main() could cause problems.

                        Also be sure to initialize it just once for any change in MA length. 
                        If it is initialized for every tick you might see crashes at times (I have seen this first hand).

                        So it would look like: */


                        var avg null;
                        var 
                        nOldLen 0;

                        function 
                        preMain() {
                            
                        setPriceStudy(true);
                            
                        setCursorLabelName("top"0);
                            
                        setCursorLabelName("sma"1);
                            
                        setCursorLabelName("bottom"2);
                            
                        setDefaultBarFgColor(Color.red0);
                            
                        setDefaultBarFgColor(Color.blue1);
                            
                        setDefaultBarFgColor(Color.green2);
                        }

                        function 
                        main(LengthPercent) {
                            if (
                        Length == nullLength 10;
                            if (
                        Percent == nullPercent 2;
                            
                            if (
                        nOldLen == || Length != nOldLen){
                                
                        avg = new MAStudy(Length0"Close"MAStudy.SIMPLE);
                                
                        nOldLen Length;
                           }
                            
                            var 
                        sma avg.getValue(MAStudy.MA);
                            var 
                        top sma * (Percent .01);
                            var 
                        bottom sma * (Percent .01);
                            
                            return new Array(
                        topsmabottom);
                        }
                         

                        /*  I believe that keeping the old value of Length and comparing it to 
                        the current length is overkill for this specific example, 
                        as changing any of the values via edit study will force eSignal to interate all the bars. 
                        This means a simple test for:

                        if (avg == null)

                        Would be enough. But I coded it this way so that if people wanted to create an EFS that would 
                        allow the Length of the MA to modifed by the EFS dynamically, they would have a template.

                        Garth  */ 
                        Attached Files

                        Comment


                        • #13
                          Is it possible the lengthy comments made the inputs disappear?
                          Heh...if it is the wrong kind of comments.

                          PHP Code:
                          Make the var declaration for the builtin a local global by placing the statement outside of main(). 
                          These are the problem lines. Get rid of the paren's after main() (so it is only main and not main()) in both instances. It seems that when they are tokenizing EFS it only looks to match the name main( and doesn't pay attention to comment lines in that case. I got caught by the same thing a short time ago and Matt had to help me figure it out. So you aren't the first to be caught by it.

                          Garth
                          Garth

                          Comment


                          • #14
                            With both EFS applied to the same chart it's easy to see the difference via the edit study menu. The version without comments has inputs while the other one doesn't.

                            PHP Code:

                            var avg null;
                            var 
                            nOldLen 0;

                            function 
                            preMain() {
                                
                            setPriceStudy(true);
                                
                            setCursorLabelName("top"0);
                                
                            setCursorLabelName("sma"1);
                                
                            setCursorLabelName("bottom"2);
                                
                            setDefaultBarFgColor(Color.red0);
                                
                            setDefaultBarFgColor(Color.blue1);
                                
                            setDefaultBarFgColor(Color.green2);
                            }

                            function 
                            main(LengthPercent) {
                                if (
                            Length == nullLength 10;
                                if (
                            Percent == nullPercent 2;
                                
                                if (
                            nOldLen == || Length != nOldLen){
                                    
                            avg = new MAStudy(Length0"Close"MAStudy.SIMPLE);
                                    
                            nOldLen Length;
                               }
                                
                                var 
                            sma avg.getValue(MAStudy.MA);
                                var 
                            top sma * (Percent .01);
                                var 
                            bottom sma * (Percent .01);
                                
                                return new Array(
                            topsmabottom);

                            Attached Files

                            Comment


                            • #15
                              Hmm...there should have been two lines in the code section that need to be fixed, but for whatever reason only one pasted and now it will not let me edit my own post to fix it (again, for whatever reason).

                              Anyway these are the lines:


                              Make the var declaration for the builtin a local global by placing the statement outside of main().
                              Matt has suggested to me in the past that declaring it inside of main() could cause problems.
                              Garth

                              Comment

                              Working...
                              X