Announcement

Collapse
No announcement yet.

Average Standard Deviation

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

  • Average Standard Deviation

    I'm trying to create a 65day average of a 65day standard deviation. Any help is greatly appreciated.

    The following code is returning "none".

    function main(nInputLength) {
    if(nInputLength == null)
    nInputLength = 65;

    var nLength = nInputLength;
    var i;
    var vSum = 0.0;
    var vstdev= 0.00;

    var vstdev= efsExternal("/Downloads/StandardDeviation.efs",0);


    if(vstdev == null) {
    return;
    }

    for(i = 0; i < nLength; i++) {
    vSum += vstdev[i];
    }

    return (vSum / nLength);

  • #2
    Re: Average Standard Deviation

    WilliamV
    Here is your code with some changes and comments explaining those changes
    Alex

    PHP Code:
    function main(nInputLength) {
    if(
    nInputLength == null)
    nInputLength 65;

    var 
    nLength nInputLength;
    var 
    i;
    var 
    vSum 0.0;
    var 
    vstdev0.00;

    var 
    vstdevefsExternal("/Downloads/StandardDeviationA.efs");//removed the ,0 which would retrieve a value
                                                                //instead of the series as required


    if(vstdev.getValue(0) == null) {//added .getValue(0) in the null check to retrieve the value from the series
    return;
    }

    for(
    0nLengthi++) {
    vSum += vstdev.getValue(-i);//added .getValue(-i) to retrieve the values from the series
    }
    /*
    instead of calculating the average using a for loop you could also do the following
    var MAofStdDDev = sma(nInputLength, vstdev);
    and then return MAofStdDev.getValue(0)
    */
    return (vSum nLength);


    Originally posted by WilliamV
    I'm trying to create a 65day average of a 65day standard deviation. Any help is greatly appreciated.

    The following code is returning "none".

    function main(nInputLength) {
    if(nInputLength == null)
    nInputLength = 65;

    var nLength = nInputLength;
    var i;
    var vSum = 0.0;
    var vstdev= 0.00;

    var vstdev= efsExternal("/Downloads/StandardDeviation.efs",0);


    if(vstdev == null) {
    return;
    }

    for(i = 0; i < nLength; i++) {
    vSum += vstdev[i];
    }

    return (vSum / nLength);

    Comment


    • #3
      Thanks Alexis!
      I have the following std dev code and I have set it for 65 days. Why does the average on this thread does not equal the average on the standard deviation efs? According to a simple excel calculation from the data export of the std dev code it should be 4.59 and this code shows it to be 2.48 on symbol SOL.

      function preMain() {
      setStudyTitle("Standard Deviation ");
      setDefaultBarFgColor(Color.blue);
      setCursorLabelName("Stdev");
      }

      function main(nLength, sPriceSource) {
      if (nLength == null) nLength = 25;
      if (sPriceSource == null) sPriceSource = "Close";

      var aSource = getValue(sPriceSource, 0, -nLength);
      if (aSource == null) return null;

      var sumX = 0;
      var sumX2 = 0;
      for (i = 0; i < nLength; ++i) {
      sumX += aSource[i];
      sumX2 += (aSource[i] * aSource[i])
      }
      var meanX = (sumX/nLength);
      var stdev = Math.sqrt((sumX2/nLength) - (meanX*meanX));

      return stdev;
      }

      Comment


      • #4
        WilliamV
        That is because the calling efs is using the default length of 25 for the standard deviation instead of 65.
        Modify the default in the called efs to 65 and you will get 4.57 as the current value (see enclosed screenshot). Alternatively you can pass the required parameters through the efsExternal() call eg
        var vstdev= efsExternal("/Downloads/StandardDeviationA.efs",65,"Close");
        Alex




        Originally posted by WilliamV
        Thanks Alexis!
        I have the following std dev code and I have set it for 65 days. Why does the average on this thread does not equal the average on the standard deviation efs? According to a simple excel calculation from the data export of the std dev code it should be 4.59 and this code shows it to be 2.48 on symbol SOL.

        function preMain() {
        setStudyTitle("Standard Deviation ");
        setDefaultBarFgColor(Color.blue);
        setCursorLabelName("Stdev");
        }

        function main(nLength, sPriceSource) {
        if (nLength == null) nLength = 25;
        if (sPriceSource == null) sPriceSource = "Close";

        var aSource = getValue(sPriceSource, 0, -nLength);
        if (aSource == null) return null;

        var sumX = 0;
        var sumX2 = 0;
        for (i = 0; i < nLength; ++i) {
        sumX += aSource[i];
        sumX2 += (aSource[i] * aSource[i])
        }
        var meanX = (sumX/nLength);
        var stdev = Math.sqrt((sumX2/nLength) - (meanX*meanX));

        return stdev;
        }

        Comment


        • #5
          That will do it.

          Words can not express how thankful I truthfully am for your help.

          Thanks as always!

          William

          Comment


          • #6
            William
            As always my pleasure
            Alex


            Originally posted by WilliamV
            That will do it.

            Words can not express how thankful I truthfully am for your help.

            Thanks as always!

            William

            Comment

            Working...
            X