Announcement

Collapse
No announcement yet.

Calculate the Moving Average of a result Var

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

  • Calculate the Moving Average of a result Var

    Hello,
    I have for example this Code:

    var temp = hhv(14,high)-llv(14,low);

    Now i want to compute the Exponential Moving Average of temp variable.

    I 've tried with both of the Built-in averages ( ema() and MAStudy()) but i didn't make it.

    Is there any way to calculate this and not only the fix prices (close,low,high etc )?

    Thank you.

  • #2
    manosfm
    To do that you need to calculate your equation in a separate function [or efs] which you then call using the efsInternal() [or efsExternal()] function . This will create a series object that you can then use as the source for the sma(), ema() etc functions
    See the EFS KnowloedgeBase for the description, syntax and examples on the use of the efsInternal() and efsExternal() functions. See also this thread for examples of this. Also search these forums as there are innumerable threads [complete with examples] on this topic (as an example see here)
    Also FYI the syntax you have in the equation hhv(14,high)-llv(14,low) is incorrect. See the examples for those functions in the related articles in the EFS KnowledgeBase

    Alex


    Originally posted by manosfm View Post
    Hello,
    I have for example this Code:

    var temp = hhv(14,high)-llv(14,low);

    Now i want to compute the Exponential Moving Average of temp variable.

    I 've tried with both of the Built-in averages ( ema() and MAStudy()) but i didn't make it.

    Is there any way to calculate this and not only the fix prices (close,low,high etc )?

    Thank you.

    Comment


    • #3
      Thank you Acm i understand it and it worked.
      Can you tell me why i can pass the parameter periods to my functions?

      var tempDenom1=null;

      function preMain()
      {
      var fp1 = new FunctionParameter("periods", FunctionParameter.NUMBER);
      fp1.setLowerLimit(2);
      fp1.setDefault(14);
      }

      function main(periods)
      {
      if(periods == null) periods=14;

      var p1Function = efsInternal("func1",periods);
      var p1 = ema(3,p1Function);

      return p2;
      }
      function func1(periods)
      {
      if(hhv(periods,high)-llv(periods,low)>0)
      {
      tempDenom1 = hhv(periods,high)-llv(periods,low);
      }
      else
      {
      tempDdenom1 = 1;
      }
      return (( close()-llv(periods,low) ) / tempDenom1)*100;
      }


      I have some mistake and doesn't pass, if i put it manual to the function it works fine.

      Thank you.

      Comment


      • #4
        manosfm
        Firstly, as I already indicated in my previous reply if you are calculating the hhv of the High and llv of the Low then you are using incorrect syntax in the hhv() and llv() functions. Refer to the related articles in the EFS KnowledgeBase for the proper syntax.
        Secondly you also have an error in the script you posted where in the main function you return p2 but do not define or calculate that variable.
        That said I am not sure I understand what you mean by “why i can pass the parameter” since in the rest of the post you seem to indicate the opposite. Even in the latter case I still do not understand what you mean as the parameter is being passed to the separate function (to verify this just place a debug statement in that function to check the value of the “periods” parameter)
        Anyhow, once you correct the errors I pointed out the script will function
        Alex


        Originally posted by manosfm View Post
        Thank you Acm i understand it and it worked.
        Can you tell me why i can pass the parameter periods to my functions?

        var tempDenom1=null;

        function preMain()
        {
        var fp1 = new FunctionParameter("periods", FunctionParameter.NUMBER);
        fp1.setLowerLimit(2);
        fp1.setDefault(14);
        }

        function main(periods)
        {
        if(periods == null) periods=14;

        var p1Function = efsInternal("func1",periods);
        var p1 = ema(3,p1Function);

        return p2;
        }
        function func1(periods)
        {
        if(hhv(periods,high)-llv(periods,low)>0)
        {
        tempDenom1 = hhv(periods,high)-llv(periods,low);
        }
        else
        {
        tempDdenom1 = 1;
        }
        return (( close()-llv(periods,low) ) / tempDenom1)*100;
        }


        I have some mistake and doesn't pass, if i put it manual to the function it works fine.

        Thank you.

        Comment


        • #5
          When i copy-paste this part of my code i forget to change some things, like p2. It was different mistake.

          But i have managed to manipulate the parameters.

          Thank you Alex.

          Comment


          • #6
            manosfm
            You are welcome
            Alex


            Originally posted by manosfm View Post
            When i copy-paste this part of my code i forget to change some things, like p2. It was different mistake.

            But i have managed to manipulate the parameters.

            Thank you Alex.

            Comment

            Working...
            X