• 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

Problems with cumulative values in Dataseries

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

    Problems with cumulative values in Dataseries

    Hi Ninjas,

    I need to use some kind of single.dimensional array, such as a normal Dataseries variable, which could be able to store a past calculation cumulative value for future use in coming OnBarUpdate. Let me explain by a simple example:

    Let's suppose a simple variable "pvar1" (double) for price variations. With every OnBarUpdate, there will be a new value for this "pvar1". Imagine that I want to accumulate every single variation in one position in a single-array, as following:

    Code:
    pvar1=Close[0]-Close[1];
    					if ( pvar1 != 0.0 )
    					{	
    						for (int x = 1; x <= 1; x++)
    						{
    							acu[x]=acu[x]+pvar1;
    							
    							Print(acu[x].ToString());;
    						}
    					}
    When I run this simple code, I can confirm that it's not possible to accumulate the value of variations, it just adds the new variation to that position in the array. I suspect that for this purpose, the dataserie class doesn't work cause that value "moves" attached to price series. So, it lets me dealing with any other kind of Arrays type, such as: ARRAY, LIST or ARRAYLIST. I can confirm that it works with ARRAY, but I couldn't work it out with LIST or ARRAYLIST, some missconfiguration. Any hints?

    Thanks
    Last edited by pstrusi; 09-07-2015, 08:44 AM.

    #2
    Hello pstrusi,

    Thank you for writing in. DataSeries in NinjaTrader 7 are set using the Set() method. Have you tried the following?
    Code:
    pvar1=Close[0]-Close[1];
    if ( pvar1 != 0.0 )
    {	
    	for (int x = 1; x <= 1; x++)
    	{
    		acu.Set(x, acu[x]+pvar1);
    		Print(acu[x].ToString());;
    	}
    }
    It is important to remember that DataSeries are indexed in reverse. So DataSeries[0] is actually the most recently added item and DataSeries[CurrentBar] is the first that was added (the oldest). In comparison, on a normal array Array[0] would be the first added item (the oldest), and the most recently added item would be Array[Array.Length - 1].

    With that being said, in the example above x is the number of bars back from the current bar. So if x equals 1, we are setting the previous bar's value.

    You can find more information on the DataSeries class in our help guide here: http://ninjatrader.com/support/helpG...ghlightsub=set
    Please let me know if you have any questions or if I may be of further assistance.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      Originally posted by pstrusi View Post
      Hi Ninjas,

      I need to use some kind of single.dimensional array, such as a normal Dataseries variable, which could be able to store a past calculation cumulative value for future use in coming OnBarUpdate. Let me explain by a simple example:

      Let's suppose a simple variable "pvar1" (double) for price variations. With every OnBarUpdate, there will be a new value for this "pvar1". Imagine that I want to accumulate every single variation in one position in a single-array, as following:

      Code:
      pvar1=Close[0]-Close[1];
      					if ( pvar1 != 0.0 )
      					{	
      						for (int x = 1; x <= 1; x++)
      						{
      							acu[x]=acu[x]+pvar1;
      							
      							Print(acu[x].ToString());;
      						}
      					}
      When I run this simple code, I can confirm that it's not possible to accumulate the value of variations, it just adds the new variation to that position in the array. I suspect that for this purpose, the dataserie class doesn't work cause that value "moves" attached to price series. So, it lets me dealing with any other kind of Arrays type, such as: ARRAY, LIST or AARAYLIST. I can confirm that it works with ARRAY, but I couldn't work it out with LIST or ARRAYLIST, some missconfiguration. Any hints?

      Thanks
      Why would you need such a complex method to simply accumulate a value? Just create a variable to hold the accumulation and add to the variable every time you have a new valid value.

      Code:
      private AccumulatedValue = 0.0;
      Code:
      double pvar1=Close[0]-Close[1];
      if ( pvar1 != 0.0 )  AccumulatedValue += pvar1;

      Comment


        #4
        Because I need to do this for several different "combinations", so in order to keep simultaneously all of them ( values ) for every combination, an array is needed

        Comment


          #5
          Michael thanks for the response. As you can see the reason of the problem is not the assignation method, it's the dataserie variable logic itself. I could prove this by changing this to a simple ARRAY. However I'll comeback to this later trying LIST or ARRAYLIST, if any progress, I´ll let it know

          Comment


            #6
            Originally posted by pstrusi View Post
            Because I need to do this for several different "combinations", so in order to keep simultaneously all of them ( values ) for every combination, an array is needed
            I see.

            Well, there are 2 ways to resolve a programming issue. One is to say: "This is my solution. How do I code it?", then describe the solution. The other is to say: "This is my problem. How do I solve it?". This does neither, so I shall have to bow out here.

            All the best in your quest.

            Comment


              #7
              Originally posted by koganam View Post
              I see.

              Well, there are 2 ways to resolve a programming issue. One is to say: "This is my solution. How do I code it?", then describe the solution. The other is to say: "This is my problem. How do I solve it?". This does neither, so I shall have to bow out here.

              All the best in your quest.
              I'll always thanks your suggestions, as I've told before, your deep level is very helpful quite often

              Comment


                #8
                Hello pstrusi,

                Thank you for the update. If you provide a working code for how you achieved what you are trying to do (with an array or however else), I believe I would understand what you are trying to do better so I could provide more helpful information.

                Thank you in advance.
                Michael M.NinjaTrader Quality Assurance

                Comment


                  #9
                  The simplest, quickest and final solution to my requirement is using a traditional ARRAY.
                  Here, all the basic steps done in order to be able to work properly as needed

                  1. Declaring ARRAY

                  #region Variables
                  double[] acu = new double[initial];
                  #endregion

                  2. Updating the Array dimension that actually will be used

                  protected override void OnStartUp()
                  {
                  acu = new double[oscillation+1];
                  }

                  3. After use if "reseting or clearing" the Array is needed, then proceed with:

                  Array.Clear(acu, 0, wpoint.Length);

                  Comment


                    #10
                    Hello pstrusi,

                    Thank you for providing your solution in case anyone else has similar inquiries.

                    Please let me know if I may be of further assistance or if you have any questions.
                    Michael M.NinjaTrader Quality Assurance

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by cirzonorkecv, Yesterday, 11:52 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post cirzonorkecv  
                    Started by rickyblah12, Yesterday, 01:01 PM
                    1 response
                    14 views
                    0 likes
                    Last Post Erwin Beckers  
                    Started by dadarara, Yesterday, 12:18 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post dadarara  
                    Started by joemiller, Yesterday, 07:33 AM
                    2 responses
                    13 views
                    0 likes
                    Last Post joemiller  
                    Started by TheGameOfProbabilities, 07-18-2019, 06:56 AM
                    7 responses
                    38 views
                    0 likes
                    Last Post DaveS
                    by DaveS
                     
                    Working...
                    X