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

Better practice to store a collection of data

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

    #16
    Originally posted by efeuvejota01 View Post
    If I would like to copy a ListSeries<int> form one to another Indicator.
    What would be the Syntax to achieve it??
    I'll respond before today is over.

    As a quick answer, if you make your ListSeries public, other indys and
    strats can easily get to that data.

    Examples soon ...

    Comment


      #17
      Thank you bltdavid​,!! No worries!!

      Last edited by efeuvejota01; 05-31-2023, 08:08 PM. Reason: repeated question....

      Comment


        #18
        Hello bltdavid​, I am sorry to say this, but I really need ​a way to remove, in some cases, the last two Pivots. I tried replace the value with "0" (zero), but the logic and the code get creasy.
        Please!! enable the RemoveAt() feature.....
        Sincerely FVJ
        Last edited by efeuvejota01; 05-31-2023, 11:16 PM. Reason: wording...

        Comment


          #19
          Perhaps just use a List<MyType> here if you want to remove them? Or a Queue or a Stack, if that is appropriate for your usage, though most people just use lists.
          Bruce DeVault
          QuantKey Trading Vendor Services
          NinjaTrader Ecosystem Vendor - QuantKey

          Comment


            #20
            Originally posted by efeuvejota01 View Post
            to communicate between Indicators when there is no other way.
            If I would like to copy a ListSeries<int> form one to another Indicator.
            I've updated the example file you cited and added some sample
            code to help you get started.

            This zip file contains a new file called MyCommon.cs, which declares
            the namespace 'My.Common'.

            Inside the My.Common namespace, you'll find the class definition for
            ListSeries<T>.

            The point of MyCommon.cs is to address the dilemma discovered
            by the OP in post 7 above -- that is, just where the heck does the
            class ListSeries<T> live?

            It lives in the namespace My.Common in the file MyCommon.cs
            located in the Indicators folder.

            You gain access to the class definition with 'using My.Common;',
            which you add to the top of your Indicator, Strategy, or AddOn script.

            Installing the attached zip file will install Indicators/MyCommon.cs.

            Enjoy!



            PS: My apologies to the OP for not having all this completely fleshed
            out when I first introduced ListSeries<T> ...
            Attached Files
            Last edited by bltdavid; 06-01-2023, 05:35 PM. Reason: Added extra details about new MyCommon.cs file

            Comment


              #21
              Originally posted by efeuvejota01 View Post
              I really need a way to remove, in some cases, the last two Pivots. I tried replace the value with "0" (zero), but the logic and the code get creasy.
              Please!! enable the RemoveAt() feature.....
              Ok, I gotcha covered ... I needed that later, too, in a different
              project. [I was reluctant to muddy the waters too much when
              I was first describing ListSeries<T>, my apologies to the OP
              who probably/kinda/sorta/maybe needed this as well.]

              Yeah, so, what's the best way to do that?
              Here's one way, use my ListStack<T> class.

              I invented ListStack<T>, which inherits from ListSeries<T>.

              Download the attached file MyCommon.cs, and overwrite the
              original file you download in the V2 example code in my previous
              post.

              In your code, you'll want to change every occurrence of the string
              'ListSeries' to 'ListStack'.

              A ListStack<T> gives you all the features of a ListSeries<T> but
              adds 3 additional methods,

              Push()
              Pop()
              Peek()

              When you need to remove the last two pivots, you'll call Pop() twice.

              Enjoy!



              PS: If you feel really bold, you can copy the Pop method from
              ListStack and add it to ListSeries, but maybe call it something
              like RemoveLast() ... feel free to play with what works best in
              your project.
              Attached Files

              Comment


                #22
                Alright, I took my own advice.

                This final version of MyCommon.cs has been updated to
                do what you (and the OP) have asked for -- I implemented
                my suggestion about RemoveLast from my previous post.

                This version of ListSeries<T> has a new method called
                RemoveLast() -- this method does the 'Pop' operation I
                introduced in ListStack<T> in my previous post.


                zzBar.Set(CurrentBar);
                zzBar.RemoveLast(); // undo the Set

                If you need to remove the last two slots, then you would
                need to call RemoveLast() twice.

                Download the attached file, overriding your previous copy.

                Enjoy!


                Attached Files

                Comment


                  #23
                  bltdavid​:
                  Thank you Very Much for all the help...

                  I hope this is the last question...

                  how would it be a the syntax of the following sentence of two lists (list01 and list02)

                  Code:
                  list01 = list00.Cast<int>().ToList();
                  for a ListSeries<T>???

                  Is analogue to the question I had related with the lists.... https://forum.ninjatrader.com/forum/...21#post1253521

                  Thank you very much!!!
                  FVJ
                  Last edited by efeuvejota01; 06-03-2023, 07:21 PM. Reason: Lack of question mark....

                  Comment


                    #24
                    Originally posted by efeuvejota01 View Post
                    Is analogue to the question I had related with the lists
                    I've updated the class definition of ListSeries<T>
                    so that you could use an existing ListSeries variable
                    when creating a new one,

                    list01 = new ListSeries<int>(list00);

                    I've basically added a new constructor that takes an
                    existing ListSeries<T> and returns a duplicate of it.

                    [EDIT: This is analogous to Bruce's post here.]

                    But first, you'll need to download the new MyCommon.cs
                    file attached below.
                    Attached Files
                    Last edited by bltdavid; 06-03-2023, 10:00 PM.

                    Comment


                      #25
                      Thank you David!!
                      Thank you Bruce!!
                      I will try to finish this!!
                      FVJ

                      Comment


                        #26
                        Good morning bltdavid​,

                        I am trying to make a new ListSeries<T> but with the source in other indicator

                        so I tried [CODE]list01 = new ListSeries<int>(NinjaTrader.Ninjascript.Indicators .list00);​[​/CODE] but it did not compile...

                        list00 is declared in the other indicator as follows

                        Code:
                        public static            ListSeries<int>        list00        = new ListSeries<int>()     {Name = "list00"};
                        Is there any syntax I can improve??

                        Thank you for your advice!!!
                        FVJ

                        Comment


                          #27
                          Originally posted by efeuvejota01 View Post
                          I am trying to make a new ListSeries<T> but with the source in other indicator

                          so I tried
                          Code:
                          list01 = new ListSeries<int>(NinjaTrader.Ninjascript.Indicators.list00);
                          but it did not compile...

                          list00 is declared in the other indicator as follows

                          Code:
                          public static ListSeries<int> list00 = new ListSeries<int>() {Name = "list00"};
                          Is there any syntax I can improve??

                          Thank you for your advice!!!
                          Ok, and what is the class name of that other indicator?
                          (I think that's your issue)

                          -=o=-

                          Here's an example:
                          Let's say you have two indicators, and their names are,

                          GoodLine
                          BetterLine

                          Let's say the GoodLine indicator has the list00 variable,
                          per your code above.

                          Inside BetterLine, you can make a copy of that list00 variable,
                          using this code,

                          Code:
                          list01 = new ListSeries<int>(NinjaTrader.NinjaScript.Indicators.GoodLine.list00) { Name = "list01" };
                          Give that a try.
                          Last edited by bltdavid; 06-09-2023, 08:31 AM.

                          Comment


                            #28
                            Hi!!
                            I tried as suggested... but no luck!!

                            Click image for larger version  Name:	image.png Views:	0 Size:	10.6 KB ID:	1255383
                            Click image for larger version  Name:	image.png Views:	0 Size:	4.4 KB ID:	1255384
                            Thank you!!!
                            FVJ​

                            Comment


                              #29
                              Did you download the latest MyCommon.cs?

                              Do you have 'using My.Common;' in both indicators?
                              Last edited by bltdavid; 06-14-2023, 01:15 AM.

                              Comment


                                #30
                                I had the previous version in the source indicator!!! now is working!!!
                                Thank you FVJ

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by mjairg, 07-20-2023, 11:57 PM
                                3 responses
                                213 views
                                1 like
                                Last Post PaulMohn  
                                Started by TheWhiteDragon, 01-21-2019, 12:44 PM
                                4 responses
                                544 views
                                0 likes
                                Last Post PaulMohn  
                                Started by GLFX005, Today, 03:23 AM
                                0 responses
                                3 views
                                0 likes
                                Last Post GLFX005
                                by GLFX005
                                 
                                Started by XXtrader, Yesterday, 11:30 PM
                                2 responses
                                12 views
                                0 likes
                                Last Post XXtrader  
                                Started by Waxavi, Today, 02:10 AM
                                0 responses
                                7 views
                                0 likes
                                Last Post Waxavi
                                by Waxavi
                                 
                                Working...
                                X