Announcement

Collapse
No announcement yet.

ema problem

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

  • ema problem

    I am having problems getting an ema of a calulated value. Normally the default for an ema is the close but instead I want to use a calulated var called 'dSum'. Logic tells me that using 'ema(21,dSum)' would give me this value, yet I am getting a very wierd plot line. Can someone please tell me what I am doing wrong.

    Thanks, Steven

  • #2
    Steven
    dSum is probably not a series which the ema() function instead requires as a source.
    You need to calculate dSum as a separate function which you then call using efsInternal(). This will create the series that you can then use as a source for ema()
    Alex

    Comment


    • #3
      Still having ema problems

      Alexis,

      I did as you suggested but when I reload the efs, eSignal gets caught in some kind of loop and hangs-up. I then have to quit the appliancation and then delete the efs so I can restart eSignal. This is getting very frustrating. Let me tell you exactally what I want to do and maybe you can help me.

      I want to modify the efs file 'AccDist.efs' so that the var 'dSum' is subrtacted from its previous value. That would work out to be 'dSum - dSumLast'. Lets assign that value to 'dMA'. Then I want an ema(7 periods) of an ema(14 periods) for 'dMA'. How do I do this.

      In MetaStock it would be written mov(mov(dma,14,E),7,E).

      Please Help, Steven

      Comment


      • #4
        Steven
        If you are encountering problems with your code then please post it and someone will be able to guide you through fixing them.
        Also you may want to read this thread where you can find detailed information and examples on how to use the efsInternal() function to do what you are trying to accomplish. More examples can be found in this thread which shows how to create studies on studies using custom variables.
        Regardless I am not sure I understand why you are going about this the difficult way. All you need to do is calculate a double exponential average of the Accumulation/Distribution study using the EFS2 builtin functions and then simply subtract the prior value of this average from its current value ie
        PHP Code:
        var myVar ema(7,ema(14,accDist()));
        var 
        myVarDiff myVar.getValue(0)-myVar.getValue(-1); 
        In the return statement you then use myVarDiff which will return the same result as you would get when using the AccdDist.efs to calculate the difference and then computing a double exponential average of that difference
        Alex

        Comment


        • #5
          Alexis,

          I apologize if I have not been following proper forum etiquette...So this time I have included my code in question. I tested out 'myVarDiff' and it outputs the proper values, but once I take a double MA of it, thats when I get an error message 'Parameter Number 2 of Function ema is invalid'. What have I done wrong with this formula?

          Thanks, Steven


          function preMain() {
          }

          function main() {
          var myVarDiff = accDist().getValue(0)-accDist().getValue(-1);
          var myVar = ema(7,ema(14,myVarDiff));

          return myVar;

          }

          Comment


          • #6
            Steven
            That error is caused by the fact that myVarDiff is not a series object (which the ema() function requires) but a value.
            You need to create a separate function in which you compute your myVarDiff and which you then call using the efsInternal() function. This will create the series object which can then be used as a source for the ema() function.
            PHP Code:
            function main(){
                var 
            myAvg ema(7,ema(14,efsInternal("myCalc")));
                return 
            myAvg;
            }
            function 
            myCalc(){
                return 
            accDist(0)-accDist(-1);//see Notes
            }
             
            //Notes:
            //While it is possible to use the getValue() method without first declaring a study [the formula engine
            //does the latter for us in the background] we can directly access the values of a study by using the 
            //barIndex parameter as shown in the example above.
            //A more efficient way is to declare the study as a global variable, intialize it in the function and 
            //then use the getValue() method to retrieve its values. See the following example
             
            var myAccDist null;//declare the study as global variable
            function myCalc(){
                if(
            myAccDist==nullmyAccDist accDist();//initalize the study
                
            if(myAccDist.getValue(-1)==null) return;//null check on oldest value used
                
            return myAccDist.getValue(0)-myAccDist.getValue(-1);

            The logic used for the efsInternal() sample code above is explained in detail in the threads I indicated earlier so you may want to go through them and try the examples provided
            Also I would suggest that you try the method I described in my prior reply ie to first compute the double exponential average of accDist() and then to calculate the difference between the prior and current values of the average. The result should be the same
            Alex

            Comment


            • #7
              Alexis,

              Thank you so much... my indicator now works. Your last example helped me understand the concept of 'efsInternal' and when to use it. But that leads me to another question. When plotting values, how did esignal know that I wanted to plot the value of 'myAvg' and not the value of 'accDist(0)-accDist(-1)'. Would it be safe to say that esignal will plot any values after the return in the 'function main()'.

              Thanks again, Steven

              Comment


              • #8
                Steven
                You are most welcome.
                What an EFS will plot is defined by the return statement in function main().
                For more information on EFS you may want to see the Tutorials and Guides that are available in the EFS KnowledgeBase.
                Alex

                Comment

                Working...
                X