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

nested lists example

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

    #16
    Hello Amedeus,

    "not anymore, since it can contain only one argument."
    A list holds an object. That object can be a class with many properties or a collection that holds many objects or a class with properties that are collections and have one class object with many collections in it. Why do you need multiple arguments?

    "each flag object would have a string Name and an int BarNb. (from the concat of both lists<int>."

    The Flag class having a string and int property is fine. from the concat of both lists? Why do you have two lists? What are these lists for? Why are they being concatenated instead of being one list?

    Do you have two distinct lists with different data, and you want to line up the indexes? Like use the index of the element in listA as the same index for listB?

    "does the query from the strategy not help figuring out what I attempt to do ?
    foreach (CustomClass.Flag thisObject in MyExampleList.Where(obj => obj.Name.Contains("flagListA") || obj.BarNb > someInt))"

    This appears to be attempting to select a CustomClass.Flag which is not making sense. Do you want a CustomClass object returned or a Flag object returned?

    If you return a CustomClass, that CustomClass would have a .Flag you can use.

    But the where of selecting CustomClass where the name string is 'flagListA' or the BarNb is someInt would work.



    CustomClass<MyFlagList<Flag>> would not be correct.

    CustomClass is not an enumerable type collection and doesn't hold another type. List, like an array, is an enumerable collection class. I'm not sure what MyFlagList is, but I don't this is a type at all and you are intending to use this as a variable name. But if that was a custom class itself, it also is not enumerable.

    A List<T>, an array T[], a Dictionary<TKey, TValue>, a KeyValuePair<TKey, TValue>, are all enumerable type collections.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Hey Chelsea, thank you very much again.

      "Why do you have two lists? What are these lists for? "
      Because they are populated in OnBarUpdate() at different times, after different conditions are met.
      They are just flags of different events of price action.
      Just fyi, I just use a certain amount of events before CurrentBar[0], this is why I remove the First() evrey new Add() when the Count() is greater than some number <-- those Lists are dynamic and always update but their Count() do not grow <-- every CustomClass object should have different data from those lists.

      And I want to concatenate those ints into one big list containing all flags Name and BarNb. <-- this would be really easy, even for me, with Dictionaries or SortedLists if the events could not happen during the same bar, I would create the dictionary/SortedList.ToList() from the concats and put it as a CustomClass property.
      But some events do happen in the same Bar : --> then we could add the DateTime in the string key and have a the BarNb as the value, but it would make it harder once we want to query CustomClass.Flag.Name... (wich appears to not make sense)

      "Why are they being concatenated instead of being one list?"
      If we could have an "AggregClass" with all the Lists<int>, with each AggregClass.Lists<int> populated at different times, I would be interested in that, I taught about this longtime ago, but it looked like out of my skills.
      Such an object might help with our CustomClass tho, if we were to add one as a CustomClass property every CustomClass.Add().

      "Do you have two distinct lists with different data, and you want to line up the indexes? Like use the index of the element in listA as the same index for listB?"
      I did not decide yet what to do with the flags within the same bar.
      But I intend to have this List of flags to return oredered by BarNb.

      "Do you want a CustomClass object returned or a Flag object returned?"
      I want both. Since those Lists are dynamic and always update, I want each CustomClass object to have a list of flags.
      Every time a CustomClass object is added, a new list of Flag objects should be added as a property of the CustomClass object.
      Last edited by Amedeus; 06-17-2022, 03:03 PM.

      Comment


        #18
        Hey Chelsea, hey everyone,

        Thank you very much for the help Chelsea, I should say "for the course" actually.

        Boom ! attached is a sample of what I was trying to accomplish : iterate through Flag objects values per CustomClass objects.
        As not perfect as it is, it behaves like wanted.
        I was not clear nor accurate with the objects, variables, types, and the methodology to get there with the population then iteration of each CustomClass objects.

        Basically with a class we are creating our own CustomType, like int or string are types, and we can fill any list<CustomType> with its characteristics(/properties).

        I did not realize this, to me the content of List<CustomClass> was "inside" CustomClass, while in reality it is elsewhere (where the list is declared) : CustomClass is just the "empty" shape/Type of the object, that we can use kinda anyhow. <-- if that makes sense.
        This is written all over but i did not catch it as such : C# Class (tutorialsteacher.com)...

        to populate MyFlagList inside each CustomClass objects,
        we populate a separate myFlagList with all the List<int> values and add each a Flag.Name.
        than we add myFlagList.OrderBy(c=>c.BarNb).ToList() as a property of CustomClass.
        then we Clear() myFlagList to have frash values every new CustomClass (this is only if we want a few flags per CustomClass objects, like in our case today).

        I have a new question for you tho :
        how come this does not output the count of MyFlagList line 183 ?
        , thisObject.MyFlagList.Count()// here I could not output an int... how is that ?
        this is what the line outputs : System.Collections.Generic.List`1[NinjaTrader.NinjaScript.Strategies.Flag], when I expected an int (20)
        Attached Files
        Last edited by Amedeus; 06-19-2022, 08:22 AM.

        Comment


          #19
          Hello Amedeus,

          This appears to be duplicating information. Why is myFlagsA being duplicated into myFlagList? Why is myFlagList being duplicated into a new CustomClass in the myExampleList?

          Why not just add the information to the myExampleList[index].MyFlagList directly without having to copy all of this information multiple times?

          If the list is related to the myExampleList[index].MyFlagList, just add the information directly to that. No need to make all of these multiple lists just to duplicate them into the CustomClass.

          If they are not related, why are you adding this list to the CustomClass?
          Last edited by NinjaTrader_ChelseaB; 06-20-2022, 08:24 AM.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            Hey Chelsea, thank you very much,

            "Why not just add the information to the myExampleList[index].MyFlagList directly without having to copy all of this information multiple times?"
            (I guess you mean it like so : myExampleList.Add( CustomClass[myExampleList.Count - 1].myFlagList().Add(); I am not sure mys syntax would work but I'm curious about how to add to a property of an existing object)
            Because I just want to have the last few flag events right before a new CustomClass is added.
            If we keep adding directly to the last CustomClass every myFlagsA events, there would be to much data between each CustomClass objects that we don't really want...

            "No need to make all of these multiple lists just to duplicate them into the CustomClass."
            maybe, I can't say a categoric no.
            But I also want the last few events of each flags : for example there could be 10 myFlagsA for 1 myFlagsB : if I need 10 myFlagsB, this would make 100 myFlagsA wich I dont think I want.

            This is about coding history, historical events, to compare previous events of each CustoClass objects (wich are events themselves)
            let me know if this does not justificates that. I could miss something about adding to a class property list, and would not mind to dodge an excess of duplication.

            I think your questions relate to the 3rd paragraph of #post17 and a List<AggregClass> made of multiple Lists<Flag>, instead of just multiple List<int>.
            But from how I described it, there still would be a copy of List<AggregClass> every new CustomClass is added.
            Can we remove(myAggregClassList.MyFlagsA.First()) ? and keep every other Lists<Flag> within myAggregClassList intact ?
            Do you think this would make the code neater than many List<int> ? and is worth it.
            Last edited by Amedeus; 06-20-2022, 10:21 AM.

            Comment


              #21
              Hello Amedeus,

              Unfortunately, I'm not understanding how this is being used or why information in lists are being duplicated twice.

              Is this just to learn how lists and linq works or is this an actual script you are building?

              Why is "FlagA_ca_sma10" being added repeatedly to a list and then copied to a new list and then copied to a new list?
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                hey Chelsea,

                this is about building a real script.
                more of a market research script to find statistical evidences.

                Why is "FlagA_ca_sma10" being added repeatedly to a list and then copied to a new list and then copied to a new list?
                I agree there might be one to many copy.
                But at the end we have different FlagA_ca_sma10 values every CustomClass object. Same for every Flag.Name.
                We can now try to compare CustomClass objects and see if there is some statistical clue coming from the MyFlagListsof each CustomClass object.

                We can add a BarsAgo property to our MyFlagList items.
                Maybe we can find some pattern querying the history of what happens every new CustomClass is added.

                I have not started yet with these MyFlagLists, but i may come back here needing help making some complex queries...
                for example I'd like to output an IList of the most frequent Flags before a new CustomClass is added.

                does this still not makes sense to you ?

                Comment


                  #23
                  Hello Amedeus,

                  No, this is still making sense to me. This script doesn't appear to do anything but copy a string several times into a list, and then copies the list into another list, which is copied again into another list. I really am not getting it.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    hey Chelsea,

                    lol. Fine.
                    every new int/flag implements an ever updating small list.
                    it does not only copy a string several times. it associates recurring strings to every new int depending on the condition of the flag <-- AgregList could abreviate those 2 lines.

                    CustomClass object could have nothing to do with a sma crossabove or whatever, but it is implemented with the small history of flags that have happened right before CustomClass happened.
                    that's all we did : associate a historical sequence of events to a specific object. <-- I dont think I can say it better. (I am curious to know how you would proceed to do such thing (underlined stuff)).

                    Anyway, thank you Chelsea, very much, I found your help really great, as always.
                    I really struggled finding a way to associate the sequence to the object.

                    Comment


                      #25
                      Hi Chelsea,

                      attached is a new sample illustrating the kind of queries that our thread made possible.

                      I had to tweak the previous sample a little but it is very similar,
                      Implement with an IEqualityComparer interface in order to use Except,
                      then we could compare CustomClass objects flags depending on properties <-- this kind of stastistical queries was our end goal.

                      yes, we still need many flags and List<Flag> copies, but I can't think of a shortcut to avoid that...

                      hope this helps getting it.
                      have a good one.
                      Attached Files

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by andrewtrades, Today, 04:57 PM
                      1 response
                      5 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by chbruno, Today, 04:10 PM
                      0 responses
                      3 views
                      0 likes
                      Last Post chbruno
                      by chbruno
                       
                      Started by josh18955, 03-25-2023, 11:16 AM
                      6 responses
                      436 views
                      0 likes
                      Last Post Delerium  
                      Started by FAQtrader, Today, 03:35 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post FAQtrader  
                      Started by rocketman7, Today, 09:41 AM
                      5 responses
                      19 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Working...
                      X