Announcement

Collapse
No announcement yet.

cumulative sum

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

  • cumulative sum

    Most other charting packages I have used have a cumulative sum function or chart type. Has anyone recreated that here? Simply put, it takes a running total of whatever is in the symbol place. This is necessary for creating an advance-decline chart (and net new highs-low, upvolume-down volume, etc...

  • #2
    It is certainly possible to accumulate values in EFS to accomplish the tasks you are referring to. For example, if I wanted to track positive volume vs negative volume, I could write:

    nPosVolume = 0;
    nNegVolume = 0;

    function main() {

    ....
    ....
    ....

    if (close()>close(-1) {
    nPosVolume += volume();
    }
    else {
    nNegVolume += volume();
    }


    }


    or you can write separate functions that will grab totals for a specific time period and call these from within your main() function. This function would simply return the cumulative total volume for the last nBars. Using this as a template, you could write functions to calc and return any value on any data type.

    function volSum( nBars ) {
    var x;
    var result=0;

    for (x=0; x<nBars; x++) {
    result := volume(-1);
    }

    return( result );

    }


    Hope this helps.

    Chris

    Comment


    • #3
      I am sorry but I don't understand the reply. I did try to put the code you listed into the wizard but it returned a blank chart.

      Can you make it really simple for a newbie like me?

      Comment


      • #4
        Tell me specifically what you are trying to accomplish and I will write up an example script for you.

        Chris

        Comment


        • #5
          A cumulative sum chart starts the calculation at the start of the data span. If more data is pulled into the chart then the calculation needs to start at the start of the new data. (Is this the reload function?)

          Anyway, this is simply a running total of the input - which is likely to be the advance-decline spread.

          Start the formual at zero. Then add each day's value to the running total from the day before. Negative numbers will automatically cause the cumulative sum value to decrease.

          Example:
          day 1 - input is 10 - *** sum is 10
          day 2 - input is -3 - *** sum is 7
          day 3 - inpurt is 4 - *** sum is 11.

          Thank you for your help and your quick response to my earlier post.

          Comment


          • #6
            mkahn:

            Attached is a simple script that shows how to implement an accumulator in EFS. This same logic can be used with any value or values that you wish to track.

            If I'm still missing the point of your original question, please let me know

            Chris
            Attached Files

            Comment

            Working...
            X