Announcement

Collapse
No announcement yet.

Help With EFS Study

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

  • Help With EFS Study

    Could someone please look at the following script and let me know how to keep the sound alert from going off on every tick. I would like the alert to be played once. As it is now it is played over and over again until the next bar.

    Thanks
    Attached Files

  • #2
    The script I posted contains JMAs that is why I posted here.

    Thanks again

    Comment


    • #3
      Take a look at the conditional I added at the question marks. This is only true at the beginning of a new bar. Remember, main() executes every tick unless you have this restraint, or you put a line in preMain() to set compute on close (and there are some global ways to do it also).

      PHP Code:


      function preMain() {
          
      setPriceStudy(true);
          
          
      /* Set the title that will appear in the study pane */
          
      setStudyTitle("JMA Vol Envelope");

          
      /* Set the label that will appear in the cursor window */
          
      setCursorLabelName("K-Upper"0);
          
      //setCursorLabelName("K-Basis", 1);
          
      setCursorLabelName("K-Lower"2);

          
      setDefaultBarFgColor(Color.blue0); // upper
          
      setDefaultBarFgColor(Color.red1); // basis
          
      setDefaultBarFgColor(Color.blue2); // lower

         
          
          
      var fp1 = new FunctionParameter("JMA_len"FunctionParameter.NUMBER);
          
      fp1.setName("JMA Length");
          
      fp1.setDefault(7);
          
      fp1.setLowerLimit(1);
          
          var 
      fp2 = new FunctionParameter("JMA_phase"FunctionParameter.NUMBER);
          
      fp2.setName("JMA Phase");
          
      fp2.setDefault(0);
          
      fp2.setLowerLimit(-100);
          
      fp2.setUpperLimit(100);

          var 
      fp3 = new FunctionParameter("nInputLength"FunctionParameter.NUMBER);
          
      fp3.setName("Volatility Length");
          
      fp3.setDefault(6);
          
      fp3.setLowerLimit(2);
          
          var 
      fp4 = new FunctionParameter("nConst"FunctionParameter.NUMBER);
          
      fp4.setName("Scaling Factor");
          
      fp4.setDefault(1);
          
      fp4.setLowerLimit(0);
          
          var 
      fp5 = new FunctionParameter("mTrendDirection"FunctionParameter.STRING);
          
      fp5.setName("Major Trend Direction");
          
      fp5.addOption"U" );
          
      fp5.addOption"D" );
          
      fp5.addOption"N" );
          
      fp5.setDefault("N");

      }


      function 
      mainJMA_lenJMA_phasenInputLengthnConstmTrendDirection) {
          var 
      vJMAHvJMALvJMAHL;
          
          var 
      Factor 1;
          if (
      nConst != nullFactor nConst;

      if (
      getBarState() == BARSTATE_ALLBARS) {
              
      myJMAHstudy = new JurikJMAStudy(JMA_len,JMA_phase,0,"High");
              
      myJMALstudy = new JurikJMAStudy(JMA_len,JMA_phase,0,"Low");
              
      myJMAHLstudy = new JurikJMAStudy(JMA_len,JMA_phase,0"HL/2");
              }
      //??????????????????????????????????????????????????????????
          
      if ( getBarState() == BARSTATE_NEWBAR) {  //added for whatever
      //??????????????????????????????????????????????????????????
          
          
      vJMAH myJMAHstudy.getValue(JurikJMAStudy.JMA0, -nInputLength);
          
      vJMAL myJMALstudy.getValue(JurikJMAStudy.JMA0, -nInputLength);
          
      vJMAHL myJMAHLstudy.getValue(JurikJMAStudy.JMA);
          if(
      vJMAH == null || vJMAL == null || vJMAHL == null ) return;
          
          var 
      vHminL 0;
          var 
      0
          
      for(0nInputLengthi++) {
          
      vHminL += (vJMAH[i] - vJMAL[i]);
          }

          
      vHminL /= nInputLength;
          
      vHminL *= Factor;
          
          
          if( 
      mTrendDirection == "U" && low() <= (vJMAHL vHminL)){
             
      drawTextRelative(0, ((vJMAHL vHminL)-.0020), "ENV BUY"Color.blackColor.whiteText.VCENTER|Text.CENTER|Text.BOLD"Arial"10"Buy");
              
      Alert.playSound("BPVolEnvBuy.wav");
          }
          
          if( 
      mTrendDirection == "D" && high() >= (vJMAHL vHminL)){
             
      drawTextRelative(0, ((vJMAHL vHminL)+.0020), "ENV SELL"Color.blackColor.whiteText.VCENTER|Text.CENTER|Text.BOLD"Arial"10"Sell");
              
      Alert.playSound("BPVolEnvSell.wav");
          }
          
          if( 
      mTrendDirection == "N"){
          }
          
          return new Array( 
      vHminL vJMAHLnullvJMAHL vHminL ); //vJMAHL placed in second spot in array
          
      }//added for whatever

      Comment


      • #4
        Thank You stevehare,

        However after making the corrections I now get a "line 94: SyntaxError: syntax error: }".

        If you remove the bracket then you start getting; "line 63: ReferenceError: myJMAHstudy is not defined.

        I appreciate the effort.

        Comment


        • #5

          Once the script is loaded it does not continue to draw the envelopes. The last place it is drawn is the last candle that the script was loaded on.
          Last edited by whatever; 01-13-2004, 05:32 AM.

          Comment


          • #6
            Could someone please tell me why this script won't work.

            Thanks
            Attached Files

            Comment


            • #7
              Interesting code, I would recommend that you start out using some debugPrintln() statements in there to print out different areas of the code to see where it is not responding as it should. The Jurik studies are premium studies (aren't they), as such, I cannot run.

              Comment


              • #8
                Here are some corrections I made ....

                1) Specify the delay in the study definition call, not in the study access call.

                2) Not a good idea to output a null. I simplified the output.

                Specific code segments that were changed follows ....

                ================================
                function main(Price, JMA_len, JMA_phase, Slope) {
                var vJMA, vJMA1, vJMA2, vJMA3, vJMA4, vJMA5, vJMAPC, vPC;

                /* initialization */

                if (getBarState() == BARSTATE_ALLBARS) {
                myJMAstudy = new JurikJMAStudy(JMA_len, JMA_phase, 0, Price);
                myJMAstudy1 = new JurikJMAStudy(JMA_len, JMA_phase, -1, Price);
                myJMAstudy2 = new JurikJMAStudy(JMA_len, JMA_phase, -2, Price);
                myJMAstudy3 = new JurikJMAStudy(JMA_len, JMA_phase, -3, Price);
                myJMAstudy4 = new JurikJMAStudy(JMA_len, JMA_phase, -4, Price);
                myJMAstudy5 = new JurikJMAStudy(JMA_len, JMA_phase, -5, Price);
                }

                /* core program */

                vJMA = myJMAstudy.getValue(JurikJMAStudy.JMA);
                vJMA1 = myJMAstudy1.getValue(JurikJMAStudy.JMA);
                vJMA2 = myJMAstudy2.getValue(JurikJMAStudy.JMA);
                vJMA3 = myJMAstudy3.getValue(JurikJMAStudy.JMA);
                vJMA4 = myJMAstudy4.getValue(JurikJMAStudy.JMA);
                vJMA5 = myJMAstudy5.getValue(JurikJMAStudy.JMA);

                if (vJMA == null || vJMA1 == null || vJMA2 == null || vJMA3 == null || vJMA4 == null || vJMA5 == null ) return;

                =============================
                and at the bottom of your code
                =============================

                vJMAPC = vJMA1 + vJMA2 + vJMA3 + vJMA4 + vJMA5;
                vPC = vJMA / vJMAPC;

                return vPC ;
                }

                ==============================



                -- Mark Jurik

                Comment


                • #9
                  Thank you for your prompt reply however I am not sure that the fixes are accomplishing what I was trying to do. I would like to get the previous JMA values. I believe what the script is doing now is offsetting the JMA values not calling the previous values.

                  I have had success calling one previous value but when I try to call more than one previous value the script does not work.

                  Again thank you for your help.

                  Comment


                  • #10
                    whatever
                    I think the syntax should be as follows (example is to retrieve the value of 3 bars ago)
                    myJMAstudy3.getValue(JurikJMAStudy.JMA,-3);
                    Hope this helps
                    Alex

                    Comment


                    • #11
                      Thank You Alexis I will give it a try.

                      I had been using;
                      vJMA2 = myJMAstudy2.getValue(JurikJMAStudy.JMA, -3, 1);
                      but it did not seem to work.

                      Thanks

                      Comment


                      • #12
                        I am trying to use the JMA High, JMA Low and JMA HL/2 instead of the "High", "Low", "HL/2" in the following script. I have included the original script and my attempt to do so. Any help will be greatly appreciated.
                        Attached Files

                        Comment


                        • #13
                          Here is a more detailed analysis as to why the EFS file "JMA PC", as posted on 28-JAN-04, would not plot. It is a helpful lesson in JavaScript nuances.

                          I want to begin this discussion by covering the two ways you can access past values of a time series produced by an eSignal study (e.g. JurikJMAStudy).

                          TECHNIQUE #1

                          The first way is to define the study as having a fixed negative offset. The format for JurikJMAStudy is ...

                          JurikJMAStudy(JMA_length, JMA_phase, offset, price_series);

                          If you want, on every bar, to access the value of JMA 5 bars back, simply set the study's offset to be -5. Your code would include these two lines ...

                          myJMAstudy = new JurikJMAStudy(JMA_len, JMA_phase, -5, "Close") ;

                          var myVal = myJMAstudy.getValue(JurikJMAStudy.JMA);

                          This method is not only the easiest to code but is also the fastest during run-time execution. (You'll see why later on).

                          TECHNIQUE #2

                          If, OTOH, the number of bars back is dynamic and may change on each bar, then obviously the above approach will not work as the lookback is constant. To attain a dynamic lookback, you need to take the following approach. In the study definition, set the offset to 0, as follows ...

                          myJMAstudy = new JurikJMAStudy(JMA_len, JMA_phase, 0, "Close") ;

                          and specify the lookback amount in the study access (getValue) . In general, the study access call has the following format ...

                          myJMAstudy.getValue(JurikJMAStudy.JMA [, -offset [, array_size]]);

                          So in the specific case given above, we can use these lines of code to attain dynamic lookback of 1 value getValue call.

                          var myLookback = your_calulation_goes_here ;
                          var myVal = myJMAstudy.getValue(JurikJMAStudy.JMA, -myLookback, 1);

                          Now here is where it gets interesting!! Everything that holds data in JavaScript is an object. For example, ..

                          439 is a number object.
                          "hello" is a string object.

                          Each object has two categories of "things" belonging to it. One is a collection of *properties* of the object, and the other is a collection of *methods* or operations you can do with that object. If you ever want to know what type of object a variable is, enter the following code in your EFS file ...

                          debugPrint(typeof(myMysteryVar)+"\n");

                          ... and look at what gets displayed in the Formula Output Window.

                          Let's go back to the getvalue format statement ...

                          myJMAstudy.getValue(JurikJMAStudy.JMA [, -offset [, array_size]]);

                          If you exclude the last parameter, as in the example ...

                          myVar = myJMAstudy.getValue(JurikJMAStudy.JMA, -5);

                          then typeof(myVar) = 'number' and you can add/subtract/divide/multiply/etc. with myVar as you would expect with any other number or variable representing a number. OTOH, is you include the last parameter, as in this example ...

                          var myVal = myJMAstudy.getValue(JurikJMAStudy.JMA, -myLookback, N);

                          then typeof(myVar) = 'Array'. You get an *Array* object, not a number object, even if there is only one element in the array. If N > 0, then you get an array whose first element corresponds to the current bar and the other elements correspond to successive bar values moving into the FUTURE. Be careful to include a sufficiently large negative offset, else you will asking eSignal to produce future market values. If N < 0, then you get an array whose first element corresponds to the current bar and the other elements correspond to successive bar values moving into the PAST.

                          For example, assuming the current barnumber is 100, then ...

                          var myArr1 = myJMAstudy.getValue(JurikJMAStudy.JMA, 0, -3);

                          produces an array of three values (price at bar 100 , bar 99 , bar 98)

                          var myArr2 = myJMAstudy.getValue(JurikJMAStudy.JMA, -3, +2);

                          produces an array of two values (price at bar 97 , bar 98)

                          All array objects must be indexed in order to get at their values. Indexing starts at zero, thus...

                          myArr1[0] yields the 1st element in the array
                          myArr1[1] yields the 2nd element in the array , etc.

                          This is a valid statement ...

                          var MySumm = myArr1[2] + myArr[0];

                          What happens when you forget to add the index values as in the following? ...

                          var MySumm = myArr1 + myArr;

                          If you guessed a *string* object, then you are a JaveScript wizard!! It's true. typeof(MySumm) = 'String'

                          Now we can see why the code in the EFS file "JMA PC" failed to run. Let's look at the relevant lines of code....

                          ////////////////////
                          vJMA = myJMAstudy.getValue(JurikJMAStudy.JMA);
                          vJMA1 = myJMAstudy1.getValue(JurikJMAStudy.JMA, -1, 1);
                          vJMA2 = myJMAstudy2.getValue(JurikJMAStudy.JMA, -2, 1);
                          vJMA3 = myJMAstudy3.getValue(JurikJMAStudy.JMA, -3, 1);
                          vJMA4 = myJMAstudy4.getValue(JurikJMAStudy.JMA, -4, 1);
                          vJMA5 = myJMAstudy5.getValue(JurikJMAStudy.JMA, -5, 1);

                          vJMAPC = vJMA1 + vJMA2 + vJMA3 + vJMA4 + vJMA5;
                          vPC = vJMA / vJMAPC;
                          ////////////////////

                          vJMA is a number object.
                          vJMA1 through vJMA5 are Array objects.
                          vJMAPC is a string object.
                          vPC is the result of dividing a number by a string.

                          This last operation should have caused an illegal operation trap to occur, posting an error message saying you can't divide a number object by a string object. The result is garbage. I fault JavaScript (or eSignal's version of JavaScript) for failing to catch this.

                          You can fix the problem easily by using this line ...

                          vJMAPC = vJMA1[0] + vJMA2[0] + vJMA3[0] + vJMA4[0] + vJMA5[0];

                          or by avoiding arrays altogether using these lines ...

                          vJMA = myJMAstudy.getValue(JurikJMAStudy.JMA);
                          vJMA1 = myJMAstudy1.getValue(JurikJMAStudy.JMA, -1);
                          vJMA2 = myJMAstudy2.getValue(JurikJMAStudy.JMA, -2);
                          vJMA3 = myJMAstudy3.getValue(JurikJMAStudy.JMA, -3);
                          vJMA4 = myJMAstudy4.getValue(JurikJMAStudy.JMA, -4);
                          vJMA5 = myJMAstudy5.getValue(JurikJMAStudy.JMA, -5);

                          or, as in technique #1, which should run faster. The reason is that in technique #1, the offset is calculated from the EFS code only once (during the creation of the study object). In method #2, the offset is calculated on every call, even if the offset value parameter is written as a constant.


                          Regards,

                          Mark Jurik
                          Jurik Research

                          Comment


                          • #14
                            Dear Mr Jurik,

                            I greatly appreciate you taking the time to reply in such depth. It has been a great help.

                            Thank you

                            Comment


                            • #15
                              JMA FISHER

                              COULD SOMEONE POST THE JMA FISHER.efs. I would appreciate it

                              Comment

                              Working...
                              X