Announcement

Collapse
No announcement yet.

average daily count

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

  • average daily count

    has someone created an .efs for calculating average daily count in the form of daily high - daily low and then averaged over 5 days and 10 days?

  • #2
    found this, but seems to have function error when loaded

    var vCntr=0;



    function preMain(){

    setStudyTitle("Average Change");

    setPlotType(PLOTTYPE_HISTOGRAM);

    setDefaultBarThickness(6);

    }



    function main(vNumberOfDays){



    //default number of days is 10 change it in the study params

    if (vNumberOfDays==null)var vNumberOfDays = 10;





    var vAverageChange=0;

    var vChangeSum = 0;



    if(getBarState()==BARSTATE_NEWBAR)vCntr++;



    if (vCntr>vNumberOfDays){ //gotta have enough days

    for(i = 0; i > -1*vNumberOfDays ; i--){ //go through the last 10 days

    vChangeSum += (close(i)-open(i)); //add up the changes

    }

    vAverageChange = vChangeSum/vNumberOfDays; //calc the average

    if (vAverageChange>0)setBarFgColor(Color.green);

    if (vAverageChange<0)setBarFgColor(Color.red);

    return vAverageChange; //draw the graph

    }

    }

    Comment


    • #3
      Re: found this, but seems to have function error when loaded

      pigfarmer
      FWIW at my end the formula is not generating any errors and is returning the correct results
      Alex


      Originally posted by pigfarmer
      var vCntr=0;



      function preMain(){

      setStudyTitle("Average Change");

      setPlotType(PLOTTYPE_HISTOGRAM);

      setDefaultBarThickness(6);

      }



      function main(vNumberOfDays){



      //default number of days is 10 change it in the study params

      if (vNumberOfDays==null)var vNumberOfDays = 10;





      var vAverageChange=0;

      var vChangeSum = 0;



      if(getBarState()==BARSTATE_NEWBAR)vCntr++;



      if (vCntr>vNumberOfDays){ //gotta have enough days

      for(i = 0; i > -1*vNumberOfDays ; i--){ //go through the last 10 days

      vChangeSum += (close(i)-open(i)); //add up the changes

      }

      vAverageChange = vChangeSum/vNumberOfDays; //calc the average

      if (vAverageChange>0)setBarFgColor(Color.green);

      if (vAverageChange<0)setBarFgColor(Color.red);

      return vAverageChange; //draw the graph

      }

      }

      Comment


      • #4
        thanks for review. found that my text editor was placing some incorrect characters. agree, the script works just fine.

        Comment

        Working...
        X