• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sum of data series

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

    Sum of data series

    Hi guys

    I'm working on an indicator in which a data series is created. This works out fine.

    Now I'd like to get the sum of all the values of the series: i.e:

    dataseries[1] + dataseries[2] + ... + dataseries[n].

    I'm sure I could do this using a 'While Loop' but is there a more direct way of accomplishing this? I've tried some c# research but haven't found anything yet.

    As ever, any advice greatly appreciated.

    #2
    Hello arbuthnot,
    Thank you for your note.

    You can use the SUM() function to sum values in that data series. For example:

    double sumValue = SUM(myDataSeries, 20);
    This will sum the values in the myDataSeries data series for the last 20 bars and save to the sumValue variable.

    Below is a link to the help guide on the SUM() function.
    http://www.ninjatrader.com/support/h...mation_sum.htm


    Please let me know if I can be of further assistance.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks very much, Chelsea, for your answer.

      I thought there must be a simple answer and there is one!

      Much obliged.

      Comment


        #4
        Hello arbuthnot,

        Thanks for the update.

        I'm glad to hear that was what you were looking for.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello arbuthnot,
          Thank you for your note.

          You can use the SUM() function to sum values in that data series. For example:

          double sumValue = SUM(myDataSeries, 20);
          This will sum the values in the myDataSeries data series for the last 20 bars and save to the sumValue variable.

          Below is a link to the help guide on the SUM() function.
          http://www.ninjatrader.com/support/h...mation_sum.htm


          Please let me know if I can be of further assistance.
          Chelsea--

          I wanted to be able to toggle the sum length (ie, 20 in your example above), so I created an int and then referenced that int in the SUM() function--but I received an error that the int does not exist in the current context.

          Do you know how I might skin this cat?

          Comment


            #6
            Originally posted by aventeren View Post
            Chelsea--

            I wanted to be able to toggle the sum length (ie, 20 in your example above), so I created an int and then referenced that int in the SUM() function--but I received an error that the int does not exist in the current context.

            Do you know how I might skin this cat?
            Chelsea--

            I found my errors:

            1. I had improperly defined the sumValue as type int instead of type double
            2. I had not included the [0] --I had just been using:

            sumValue = SUM(myDataSeries, length);

            To correct the problem, I:

            1. Changed sumValue to type double
            2. Added in the BarsAgo nomenclature, so now the line read:

            sumValue = SUM(myDataSeries, length)[0];

            Everything now works great.

            Hopefully this will help someone else in the future...

            Comment


              #7
              Hi aventeren,

              Thanks for pointing that out. I was missing the [0] from the SUM call. This would be needed to return a value and not a series.

              And yes, the value does need to be a double.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by aventeren View Post
                Chelsea--

                I wanted to be able to toggle the sum length (ie, 20 in your example above), so I created an int and then referenced that int in the SUM() function--but I received an error that the int does not exist in the current context.

                Do you know how I might skin this cat?
                Except that if you are changing the length, you are not getting correct values, because reading the code for that class reveals that it was written with the assumption of a fixed value for length.

                Comment


                  #9
                  Originally posted by koganam View Post
                  Except that if you are changing the length, you are not getting correct values, because reading the code for that class reveals that it was written with the assumption of a fixed value for length.
                  I failed to point out that I had defined a new variable for the score length:

                  //Variables
                  private int length = 20; // Variable to define how many bars to include in the series sum (in this case, 20)

                  Does that help?

                  Comment


                    #10
                    Originally posted by aventeren View Post
                    I failed to point out that I had defined a new variable for the score length:

                    //Variables
                    private int length = 20; // Variable to define how many bars to include in the series sum (in this case, 20)

                    Does that help?
                    As long as you are not dynamically changing the length. If you define the length as a variable, then use that length, that is just fine.

                    Comment


                      #11
                      Originally posted by koganam View Post
                      As long as you are not dynamically changing the length. If you define the length as a variable, then use that length, that is just fine.
                      I'm a static kind of dude, Koganam! Thanks for the reminder...

                      Comment


                        #12
                        Dynamic Length?

                        Thanks everybody for all that information in the prior thread, it has helped me to understand why my indicator is acting wonky. Has anybody developed a similar SUM method that takes dynamic length into consideration?

                        Comment


                          #13
                          Hi CB

                          When I started this thread (a bit of time back) I was trying to add a number of data series and Chelsea advised me to use the SUM method.

                          I'm no longer using that approach but, to refer to your question, I have recently been working on an indicator, just as an experiment, using a dynamic (i.e. non-constant) period.

                          Effectively, I've been using Bars.BarsSinceSession to determine the length or period, so that if there have been n bars in the session, the indicator length would be n for that bar.

                          So just say I was using an EMA, the code would be:

                          Code:
                          EMA(Bars.BarsSinceSession)[0]
                          Is this similar to your approach?

                          Comment


                            #14
                            Originally posted by cb4gusto22 View Post
                            Thanks everybody for all that information in the prior thread, it has helped me to understand why my indicator is acting wonky. Has anybody developed a similar SUM method that takes dynamic length into consideration?
                            I necessarily had to develop that so that I could develop indicators that have periods that adjust dynamically to the period of the dominant cycle, but I am not giving it away. My apologies.

                            On the other hand, as we are a commercial outfit, everything is negotiable.
                            Last edited by koganam; 06-22-2014, 12:10 AM.

                            Comment


                              #15
                              Hi arbuthnot and koganam,

                              Thanks for the Bars.BarsSinceSession tip. I actually figured out that my indicator was not working correctly due to another problem which I've fixed, but its good to know the limitations of SUM and that solutions are available. As for SUM, I mistakenly assumed that there needed to be a minimum of n bars before SUM would work, but that's not correct as the method accounts for n-1, n-2, ... bars as well. Regards

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jjnc2006, Today, 07:36 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post jjnc2006  
                              Started by futurenick, Today, 06:26 AM
                              1 response
                              11 views
                              0 likes
                              Last Post nkhoi
                              by nkhoi
                               
                              Started by NinjaCustomer, Today, 12:29 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_ShawnB  
                              Started by Steve L, Today, 11:32 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post Steve L
                              by Steve L
                               
                              Started by prabbala, Today, 10:41 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post prabbala  
                              Working...
                              X