Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to sync arraylist (or similar collection) to current bars?

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

    How to sync arraylist (or similar collection) to current bars?

    I am working on a strategy with a very large amount of instruments (200-2000). I have found that if I call indicators by the standard methods in NinjaTrader, the memory usage quickly blows up.

    For reference, please see my related post:



    To correct this, I have moved all of my indicator calculations inside of my strategy, and call them using custom functions rather than the NinjaTrader ones.

    My question is:
    - For the ADX calculation, there are 7 separate DataSeries that are typically stored
    > dmPlus, dmMinus, sumDmPlus, sumDmMinus, sumTr, tr, ADX

    - I would like to make a single DataSeries that contains all of these items, by creating my own class

    Code:
    public class iADX
    {
    	public double dmPlus;
    	public double dmMinus;
    	public double sumDmPlus;
    	public double sumDmMinus;
    	public double sumTr;
    	public double tr;
    	public double ADX;
    }
    
    ...
    ...
    
    private DataSeries[] cADXs = new DataSeries[numberInstruments]; 
    
    ...
    
    for (int i = 0; i <= numberInstruments; i++)
    {
       cADXs[i] = new DataSeries(this);
    }
    Is there any way to code this so that I can generate a collection of iADX members, and also have it synced to the bars (like a DataSeries would be?)

    For example:
    Code:
    for (int i = 0; i <= numberInstruments; i++)
    {
       cADXs[i] = new iADX;
    }
    
    ...
    cADX[i].dmPlus = someNumber
    cADX[i].dmMinus = someOtherNumber
    Last edited by kbeary33; 07-12-2013, 07:48 PM.

    #2
    Note that the closest that I think that I have come would be to use something like this:

    Code:
    [Description("Relative Ranking System")]
    public class MyRankingSystem : Strategy
    {
    
    public class iADX
    {
       public DataSeries dmPlus = new DataSeries(this);
       public DataSeries dmMinus = new DataSeries(this);
       public DataSeries sumDmPlus = new DataSeries(this);
       public DataSeries sumDmMinus = new DataSeries(this);
       public DataSeries sumTr = new DataSeries(this);
       public DataSeries tr = new DataSeries(this);
       public DataSeries ADX = new DataSeries(this);
    }
    Unfortunately, it seems like I can't use the keyword "this" from inside the iADX class. Is there any way of referencing the "this" keyword, as it would be in the context of the overall MyRankingSystem code? (ie, anywhere outside of the iADX class block)

    Comment


      #3
      Hello kbeary33,

      Custom classes inside of NinjaTrader are not something that is not supported.

      "this" is also just a reference of the current class, which you may not want to initialize inside of your embedded class.
      The `this` keyword clarifies access to the current instance of a type, or declares an indexer on the type.


      With that said, if you would only like one object with multiple DataSeries you may want to look into an Array. This way you may have an array of DataSeries.
      Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


      Note that Arrays are also not supported but would be easier to work with instead of a class.
      JCNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      37 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      23 views
      0 likes
      Last Post PaulMohn  
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      162 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      98 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      152 views
      2 likes
      Last Post CaptainJack  
      Working...
      X