Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

List Array

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

    List Array

    I need to create a list Array of 8 lists

    List<NinjaTrader.NinjaScript.Indicators.MyIndicato r.MyClass> MYLIST= new List<NinjaTrader.NinjaScript.Indicators.MyIndicato r.MyCustomClass>();

    How do I make my Array of Lists

    #2
    Hello ballboy11,

    Thanks for the post.

    Please see this publicly available link that shows how to make a list of lists in C#.

    I seem to be having some trouble wrapping my head around the idea of a Generic List of Generic Lists in C#. I think the problem stems form the use of the &lt;T&gt; argument, which I have no prior


    For example, to make a list of NinjaScript object lists:

    Code:
    List<List<NinjaTrader.NinjaScript.Indicators.SMA>> mylist = new List<List<NinjaTrader.NinjaScript.Indicators.SMA>>();
    			mylist.Add(new List<SMA> {SMA(14), SMA(20)});
    			mylist.Add(new List<SMA> {SMA(27), SMA(30)});
    			
    			foreach(List<SMA> subList in mylist)
    			{
    				foreach(SMA item in subList)
    				{
    					Print(item[0]);
    				}
    			}
    Please let us know if we may be of any further assistance.

    Comment


      #3
      I wasn't sure if to post this here, or in a new thread.

      1st Question: In the code that Chris provided in post #2, what would the printout be? Would there be a SMA(14),SMA(20),SMA(27),SMA(30) for every bar loaded? If so, what index value in the array would SMA(14)[0] be (as an example)?

      I am trying to use the ArrayList in a similar fashion as in the Swing indicator, but in my UseCase, I want the Array element [0] to be the most recent value of a particular calculated value. In the Swing indicator case the element[0] was the oldest value, not the last one added.

      There are not going to be values on every bar, but I would like to compare element[1] to element[0] to determine which one is higher or lower.

      Is there a way to insure the elements are in this order?
      Last edited by EminiTrader; 05-19-2021, 07:14 PM. Reason: minor edits for misspellings

      Comment


        #4
        Hi EminiTrader, thanks for posting.

        You can copy/paste the code and test it to see the output. Assuming this piece of code is in OnBarUpdate, it would print the value of each bar starting at SMA(14) and ending at SMA(30).

        I made a single dot swing indicator here to help focus on exactly where the swing value starts, that could help you in this scenario:
        https://ninjatrader.com/support/foru...-indicator-nt8

        Another good way to test the output is to use Print() and print out the swing value and the Time[0] value as well, that will give you a value and a time stamp to know exatly where the swing started.

        Best regards,
        -ChrisL

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        571 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        548 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X