Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 algospoke, Yesterday, 06:40 PM
                    2 responses
                    22 views
                    0 likes
                    Last Post algospoke  
                    Started by ghoul, Today, 06:02 PM
                    3 responses
                    14 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by jeronymite, 04-12-2024, 04:26 PM
                    3 responses
                    45 views
                    0 likes
                    Last Post jeronymite  
                    Started by Barry Milan, Yesterday, 10:35 PM
                    7 responses
                    21 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by AttiM, 02-14-2024, 05:20 PM
                    10 responses
                    181 views
                    0 likes
                    Last Post jeronymite  
                    Working...
                    X