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

How to create an array independent of the main instrument dataseries index?

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

    How to create an array independent of the main instrument dataseries index?

    Hi Ninjas,

    This should be a very simple question to answer, but I need to confirm it in order to continue a debugging of my script's logic.

    I need to create a simple one-dimension array that keeps its values by its own index, totally independent of the instrument bars-object dataseries index, I mean, regardless changes in the instrument data, I want that my array keeps its values according to its own index.

    I'm not sure yet, but I think, some how, the instrument dataseries index changes affect the independent array values.

    So, if the instrument dataseries index doesn't affect a single array, should this work?

    Code:
    #region Variables
    double[] vv = new double[initial];
    #endregion
    
    protected override void OnStartUp()
    {
      vv = new double[initial+variation];	
    }
    
    protected override void OnBarUpdate()
    {
      // use array, for example this loop
      for (int i = 1; i <= max; i++)
      {
    	vv[i]=Close[i-1];
      }
    }
    Notice that I'm trying to assign values to the vv array under its own index, but with values of the instrument dataseries with its main index.

    So my question is: Will that loop work properly assigning those values to the array and keeping them ?
    Last edited by pstrusi; 10-07-2015, 11:08 AM.

    #2
    Originally posted by pstrusi View Post
    Hi Ninjas,

    This should be a very simple question to answer, but I need to confirm it in order to continue a debugging of my script's logic.

    I need to create a simple one-dimension array that keeps its values by its own index, totally independent of the instrument bars-object dataseries index, I mean, regardless changes in the instrument data, I want that my array keeps its values according to its own index.

    I'm not sure yet, but I think, some how, the instrument dataseries index changes affect the independent array values.

    So, if the instrument dataseries index doesn't affect a single array, should this work properly?

    Code:
    #region Variables
    double[] acu = new double[initial];
    #endregion
    
    protected override void OnStartUp()
    {
    acu = new double[oscillation+1];	
    }
    
    protected override void OnBarUpdate()
    {
      // use array
    }
    Thanks, looking forward
    No collection's index has anything to do with any other collection's index, unless you gate your processing to tie them together. Even then, there is no dependence, just a coded correspondence.

    Comment


      #3
      Summarizing: you can create arrays that will work with their own indexes without any interference

      As in the example, will that snippet work properly ? Notice that I'm assigning values that come from another array, so?


      Note: I'm sorry I changed a little bit the example for my research purpose

      Comment


        #4
        Originally posted by pstrusi View Post
        Hi Ninjas,

        This should be a very simple question to answer, but I need to confirm it in order to continue a debugging of my script's logic.

        I need to create a simple one-dimension array that keeps its values by its own index, totally independent of the instrument bars-object dataseries index, I mean, regardless changes in the instrument data, I want that my array keeps its values according to its own index.

        I'm not sure yet, but I think, some how, the instrument dataseries index changes affect the independent array values.

        So, if the instrument dataseries index doesn't affect a single array, should this work?

        Code:
        #region Variables
        double[] vv = new double[initial];
        #endregion
        
        protected override void OnStartUp()
        {
          vv = new double[initial+variation];	
        }
        
        protected override void OnBarUpdate()
        {
          // use array, for example this loop
          for (int i = 1; i <= max; i++)
          {
        	vv[i]=Close[i-1];
          }
        }
        Notice that I'm trying to assign values to the vv array under its own index, but with values of the instrument dataseries with its main index.

        So my question is: Will that loop work properly assigning those values to the array and keeping them ?
        My original statement stands. What you assign to values in vv is of no relevance to what exist in the Close dataSeries. Assign whatever you want: they are just values; their provenance is irrelevant.

        Comment


          #5
          Thank you very much Koganam, a relief to have your insight in this forum

          Comment


            #6
            Hello pstrusi,

            koganam is correct. Each collection uses its own index and is not affected by another collection's index.
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Probably I'm not right in this post, but just to know:
              does Ninja ALWAYS reset any variable (a simple one as well as an array) after a BarUpdate, or just sometimes, i.e. in some specific cases or with some specific variables ?
              I noticed this reset especially with MultiSeries data.

              Comment


                #8
                Hello AlexAlex,

                Thank you for your inquiry and welcome to the NinjaTrader Support Forum!

                Can you please clarify what you mean by a variable being reset in OnBarUpdate()?

                Are you declaring the variable inside of OnBarUpdate()?

                Doing this would make the variable a local variable; only available to that particular call of OnBarUpdate().

                If you would like a variable to remain constant, without being reset, you would need to declare this variable inside of the class rather than the method.
                Zachary G.NinjaTrader Customer Service

                Comment


                  #9
                  Alex, if you're dealing with variables as usual ( declared outside of OnBarUpdate ) , NT won't reset any variable or changes any value whenever a new tick comes in, it will always depend on your logic, unless you're talking about specific situations as addressed by Zachary. Review your logic and post your doubts, NT has a great support team and they will help you out.

                  Comment


                    #10
                    Actually I didn't know about a different effect of the variables depending on where they are declared, and I'll appreciate if someone may provide me with a link for further study of this.
                    In any case, the variables that I mean (either a simple Variable1 or an array like Var[0]) surely receive their computed values in the OnBarUpdate() section, but often lose those values after the new bar has occurred. For this reason, should I need to compare values among different timeframes, this is not possible since the old variables appear to be reset to "0" or to "" after the BarUpdate.
                    Multiseries solutions like Closes[i] cannot be always helpful - for istance because the data and instruments that I need to retrieve were previously "sorted", so they can't be identified with the known original arrays.
                    I try to make it clear with an example: let's say I have a few lists of instruments and data, then I arrange them according to my criteria, then I want to see how they changed in a next bar: for this purpose I may have to compare DATA[i, previous] with DATA[i, actual].
                    The problem is that i doesn't necessarily refers to the same instrument because the old [i] index, and the related instrument, have possibly become [k] after the arrangement.
                    Therefore, how am I supposed to pass my sorted data to the next timeframe ?

                    Comment


                      #11
                      Originally posted by AlexAlex View Post
                      Actually I didn't know about a different effect of the variables depending on where they are declared, and I'll appreciate if someone may provide me with a link for further study of this.
                      ref: https://www.google.com/search?source...64l3.15231j0j7
                      In any case, the variables that I mean (either a simple Variable1 or an array like Var[0]) surely receive their computed values in the OnBarUpdate() section, but often lose those values after the new bar has occurred. For this reason, should I need to compare values among different timeframes, this is not possible since the old variables appear to be reset to "0" or to "" after the BarUpdate.
                      Multiseries solutions like Closes[i] cannot be always helpful - for istance because the data and instruments that I need to retrieve were previously "sorted", so they can't be identified with the known original arrays.
                      I try to make it clear with an example: let's say I have a few lists of instruments and data, then I arrange them according to my criteria, then I want to see how they changed in a next bar: for this purpose I may have to compare DATA[i, previous] with DATA[i, actual].
                      The problem is that i doesn't necessarily refers to the same instrument because the old [i] index, and the related instrument, have possibly become [k] after the arrangement.
                      Therefore, how am I supposed to pass my sorted data to the next timeframe ?
                      The index of a collection is increased when a new value is added to the collection, so whatever you had at index i is now identified and held at index i+1. That is how you compare the current value to the past value at the supposed index: compare the value held at index i+1 to that held at index i.

                      What are you sorting, and why?

                      Read up on Collections in c#.

                      Comment


                        #12
                        First of all, thanks for your attention.
                        My main problem is not the sorting, but the fact that most of my variables and arrays are RESET to 0 or to "" after each BarUpdate, forbidding me to make comparisons among different bars, while MultiSeries functions like Closes[i] sometimes don't help me (or are even part of the problem).
                        Let's say in this simpler way: which variables are always reset at a new bar, and which are not, or what must I do in order to avoid such resets and to store data from previous bars (please without MultiSeries statements) ?

                        Comment


                          #13
                          Originally posted by AlexAlex View Post
                          First of all, thanks for your attention.
                          My main problem is not the sorting, but the fact that most of my variables and arrays are RESET to 0 or to "" after each BarUpdate, forbidding me to make comparisons among different bars, while MultiSeries functions like Closes[i] sometimes don't help me (or are even part of the problem).
                          Let's say in this simpler way: which variables are always reset at a new bar, and which are not, or what must I do in order to avoid such resets and to store data from previous bars (please without MultiSeries statements) ?
                          What you are asking is too abstract. You will have to show us what you have written, so that we can see what might be wrong.

                          Offhand, I would say that you probably have a scoping issue. You have to declare your variables with class scope if they are to survive bar updates. It sounds like you may have declared them with local scope.

                          Comment


                            #14
                            Then I'll declare my variables elsewhere/otherwise.
                            Thank you.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by TheMarlin801, 10-13-2020, 01:40 AM
                            20 responses
                            3,914 views
                            0 likes
                            Last Post Bidder
                            by Bidder
                             
                            Started by timmbbo, 07-05-2023, 10:21 PM
                            3 responses
                            150 views
                            0 likes
                            Last Post grayfrog  
                            Started by Lumbeezl, 01-11-2022, 06:50 PM
                            30 responses
                            805 views
                            1 like
                            Last Post grayfrog  
                            Started by xiinteractive, 04-09-2024, 08:08 AM
                            3 responses
                            11 views
                            0 likes
                            Last Post NinjaTrader_Erick  
                            Started by Johnny Santiago, 10-11-2019, 09:21 AM
                            95 responses
                            6,194 views
                            0 likes
                            Last Post xiinteractive  
                            Working...
                            X