Announcement

Collapse
No announcement yet.

Finding Absolute Value of a Series

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

  • Finding Absolute Value of a Series

    Hi Alexis C. Montenegro ,

    Thanks for your previous posts on external function.

    I am trying to plot a moving average of the absolute value of the difference between 2 moving averages.

    in other words a moving average of abs( (sma(100,close(0))-sma(50,close(0))) )
    The following program works, but I can not seem to get the absolute function working when it is added.

    Thanks




    function preMain() {

    setStudyTitle("SMA Test");
    setCursorLabelName("Zero", 0);
    setCursorLabelName("SMA", 1);
    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.red, 1);

    var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
    fp1.setLowerLimit(1);
    fp1.setDefault(50);
    }

    function main(Length) {

    var vZero = 0;
    var nMove = efsInternal("range");
    var vSmooth = ema(Length,nMove);

    return new Array (vSmooth, vZero);
    }

    function range () {

    return (sma(100,close(0))-sma(50,close(0))); // Actually want abs( (sma(60,close(0))-sma(30,close(0))) );
    }

  • #2
    Colebeach
    abs() is a method of the JavaScript Math object so you need to write Math.abs(your_expression)
    See this article in the EFS KnowledgeBase for the complete description and examples of the Math object
    Alex


    Originally posted by Colebeach View Post
    Hi Alexis C. Montenegro ,

    Thanks for your previous posts on external function.

    I am trying to plot a moving average of the absolute value of the difference between 2 moving averages.

    in other words a moving average of abs( (sma(100,close(0))-sma(50,close(0))) )
    The following program works, but I can not seem to get the absolute function working when it is added.

    Thanks




    function preMain() {

    setStudyTitle("SMA Test");
    setCursorLabelName("Zero", 0);
    setCursorLabelName("SMA", 1);
    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarFgColor(Color.red, 1);

    var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
    fp1.setLowerLimit(1);
    fp1.setDefault(50);
    }

    function main(Length) {

    var vZero = 0;
    var nMove = efsInternal("range");
    var vSmooth = ema(Length,nMove);

    return new Array (vSmooth, vZero);
    }

    function range () {

    return (sma(100,close(0))-sma(50,close(0))); // Actually want abs( (sma(60,close(0))-sma(30,close(0))) );
    }

    Comment


    • #3
      Thanks

      Thanks for that. Set me on the right path !
      Originally posted by Alexis C. Montenegro View Post
      Colebeach
      abs() is a method of the JavaScript Math object so you need to write Math.abs(your_expression)
      See this article in the EFS KnowledgeBase for the complete description and examples of the Math object
      Alex

      Comment


      • #4
        Colebeach
        You are welcome
        Alex


        Originally posted by Colebeach View Post
        Thanks for that. Set me on the right path !

        Comment

        Working...
        X