Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Creating my own array of Bars: A technical question

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

    Creating my own array of Bars: A technical question

    I need to create my own array of price bars object as an array of doubles because it won't coincide with the chart regular bars object. Since I understand NT was created in C#, I was wondering how to create an array without knowing previously its total length, since it will be adding new bars to the object as new data comes in. I've read in several forums that many programmers use List<> cause it allows this function, but I'd like to know hot NT adds new price bars in a regular array. I'd highly appreciate any hint or suggestion about it.

    Edit 1:
    Is this a possible way? Using Array.Resize( );

    Thanks!
    Last edited by pstrusi; 12-03-2019, 12:36 PM.

    #2
    Hello pstrusi,

    In this case I wouldn't really be able to provide much insight here as we are referring an internal code which is not directly exposed as source code in NinjaScript.

    The ISeries<T> is an interface with a generic type parameter. This allows other objects to implement it with a given type to become a series of that type. How that is used internally and how the objects are constructed with the generic would be unknown.

    Other collections like BarsArray is just an array of the type bar: Bar[], however the array is constructed while knowing its length. Random bar series are not being added after the BarsArray is constructed, the count is known ahead of time so a fixed indexing system or an array can be used.

    For your use case a List<T> can be used if you do not have a set count to begin with or if you need to not sync the amount of bars for the chart.
    You could also use a Series<T> for this use case if you needed as many slots as bars or if you wanted to sync with a secondary added series and its amount of bars.






    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse, thanks a lot for your response, I've taken note of your suggestions.

      I'm still figuring out the best way to go. As you say, I don't need to be in sync with bars of charts, I'm just creating my own dataseries to work with. It seems that Using Array.Resize( ) could be a simpler way to set it.

      Once again, thanks for your help

      Comment


        #4
        Hello pstrusi,

        You could certainly go that route as well, it really just depends on how you wanted to form the logic and if you wanted to take that into account. If you want to use an index based system for the data, both an array or a list will do that for you these are very similar types. I could suggest looking into each type a little further to see which may provide more benefits toward your specific use.

        Both types have specific methods and properties which tailor toward their uses so looking through the MSDN documentation could help to make a decision here.

        Another factor is that a list can become an array or an array can become a list so this is heavily going to fall on preference as to which is used, you can always convert into a different type if needed.

        Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.

        Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.



        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Sorry for intervening, but why don't you just use the series, as in the help guide?
          Here is a part of my code using series

          Code:
          public class Divergence : Strategy
          {    
              private DMI DMI1;
              private int flatDMIbar, flatDMIbar0;
              private bool FlatInd, FlatIndBar;
              private Series<double>        FlatDMI;    
          ...
          else if (State == State.Configure)                
                      {
                          AddDataSeries(Data.BarsPeriodType.Tick, 1);
                          AddDataSeries(Data.BarsPeriodType.Minute, 5);               
                      }    
          else if (State == State.DataLoaded)
          {
              DMI1            = DMI(Closes[2], Convert.ToInt32(DmiPeriod));       
              FlatDMI = new Series<double>(DMI(Closes[2], Convert.ToInt32(DmiPeriod)), MaximumBarsLookBack.Infinite);   // Synchronize the custom series with series [2] (5min)
          }
          protected override void OnBarUpdate()
          {
               if (IsFirstTickOfBar)
               {                    
                   if (Math.Abs(DMI1[1] - DMI1[2]) < 0.0001)   // If DMI[1] = DMI[2] start recording DMI flat parts 
                   {
                        FlatDMI[0] = DMI1[1];                            
                         FlatInd = true;
                          if (!FlatIndBar)
                           {
                                flatDMIbar = CurrentBar - 2;   // Record the Bar Index of the Flat DMI start       
                                FlatIndBar = true;    
                             }
          
          
                        }
                         else
                          {    // Reset recording on first DMI[1] != DMI[2]
                               FlatInd = false;
                               FlatIndBar = false;
          
                            }
                         }
          .....
          }

          Comment


            #6
            Hi itrader46,

            Cause what I want is a special bar series ( that triggers under certain conditions ) that doesn't match with the original chart's bar series.

            Comment


              #7
              Yeah, I know now what you mean.. do you have any solution yet, that you will be willing to share?

              Comment


                #8
                To itrader46:

                Nope, I didn't figure a solution out cause I had to stop that research idea temporarily.

                Comment


                  #9
                  Hi pstrusi. I figured it out eventually, but I'm now advised to use Lists for performance and simplicity reasons. Have a look on StackOverflow for more info

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by SantoshXX, Today, 03:09 AM
                  0 responses
                  13 views
                  0 likes
                  Last Post SantoshXX  
                  Started by DanielTynera, Today, 01:14 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post DanielTynera  
                  Started by yertle, 04-18-2024, 08:38 AM
                  9 responses
                  42 views
                  0 likes
                  Last Post yertle
                  by yertle
                   
                  Started by techgetgame, Yesterday, 11:42 PM
                  0 responses
                  14 views
                  0 likes
                  Last Post techgetgame  
                  Started by sephichapdson, Yesterday, 11:36 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post sephichapdson  
                  Working...
                  X