Announcement

Collapse
No announcement yet.

How to Average?

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

  • How to Average?

    I have this variable

    TotVol=close(0, sym("$TVOL")) + close(0, sym("$TVOLA"))+close(0, sym("$TVOLQ"));

    which plots just fine.

    I want to find the 10 day average of this variable

    How do I do that?

    AvgVol=sma(10,TotVol()); ??

    or

    AvgVol=sma(10,getValue(TotVol())); ??

    or what?

    Thanks. PD

  • #2
    Re: How to Average?

    perrydolia
    In order to use a built-in study [such as the sma() function] with a custom source the latter has to be a series which TotVol is not as that variable is a single value.
    To create a series you need to calculate your equation in a separate function or external efs which you then call using the efsInternal() or efsExternal() functions. This series created by the efsInternal() or efsExternal() functions can then be used as a source for the built-in studies. For the description of the efsInternal() and efsExternal() functions and the required syntax see the links above which will take you to the corresponding articles in the EFS KnowledgeBase.
    Also search the forums as there are literally hundreds of examples showing how to create studies of custom variables
    Alex


    Originally posted by perrydolia
    I have this variable

    TotVol=close(0, sym("$TVOL")) + close(0, sym("$TVOLA"))+close(0, sym("$TVOLQ"));

    which plots just fine.

    I want to find the 10 day average of this variable

    How do I do that?

    AvgVol=sma(10,TotVol()); ??

    or

    AvgVol=sma(10,getValue(TotVol())); ??

    or what?

    Thanks. PD

    Comment


    • #3
      How do I calculate that TotVol expression (below) "in a separate function"?

      Thanks again,

      PD

      Comment


      • #4
        perrydolia
        Just create a separate function within your efs and calulate your equation in that eg
        PHP Code:
        function your_function_name(){
            var 
        your_variable_name your calculations here
           
        return your_variable_name;

        As I suggested in my previous reply see the article on the efsInternal() function as it includes an example of how to do what you want
        Alternatively create a separate efs to calculate your equation and then call that using the efsExternal() function. Also in this case you will find an example of how to do it in the article I linked in my previous reply
        Alex


        Originally posted by perrydolia
        How do I calculate that TotVol expression (below) "in a separate function"?

        Thanks again,

        PD

        Comment

        Working...
        X