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

New DataSeries and Trimming the Fat

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

    New DataSeries and Trimming the Fat

    Two questions, possibly related.

    1. In a strategy, I am setting myData = new DataSeries(this,MaximumBarsLookBack.Infinite); numerous times. I am declaring myData as a DataDeries at the top of the strategy method, and setting the new myData within the strategy logic when I need to "reset" the DataSeries and start from scratch many times within the strategy loop.

    This is a huge memory hog. After enough iterations, RAM is maxed out, and everything grinds to a near standstill.

    Is there a better way to do this? Does setting myData = new DataSeries simply make a new DataSeries without erasing the old one?

    2. Looking in the debugger a DataSeries declared in my strategy, I see references to buffers for each and every of the indicators in NT. Is NT seriously allocating memory for each indicator for each DataSeries object? Is NT calculating each indicator, regardless if I reference that indicator or not?

    Is there a way I can remove all of the indicators that I do not want at the time? I tried this, but all of the default @ indicators magically reappeared. I would like to make NT as streamlined as possible. Suggestions?

    #2
    Can you post some code, that maxes out ram, without revealing you secret details?

    #1 can take many meanings... "at the top" ? of what? OnBarUpdate? OnStartUp? Initialize?





    Originally posted by Serac View Post
    Two questions, possibly related.

    1. In a strategy, I am setting myData = new DataSeries(this,MaximumBarsLookBack.Infinite); numerous times. I am declaring myData as a DataDeries at the top of the strategy method, and setting the new myData within the strategy logic when I need to "reset" the DataSeries and start from scratch many times within the strategy loop.

    This is a huge memory hog. After enough iterations, RAM is maxed out, and everything grinds to a near standstill.

    Is there a better way to do this? Does setting myData = new DataSeries simply make a new DataSeries without erasing the old one?

    2. Looking in the debugger a DataSeries declared in my strategy, I see references to buffers for each and every of the indicators in NT. Is NT seriously allocating memory for each indicator for each DataSeries object? Is NT calculating each indicator, regardless if I reference that indicator or not?

    Is there a way I can remove all of the indicators that I do not want at the time? I tried this, but all of the default @ indicators magically reappeared. I would like to make NT as streamlined as possible. Suggestions?

    Comment


      #3
      @sledge: Sure thing. Thanks for the reply. Below is a skeleton:

      Code:
      namespace NinjaTrader.Strategy
      {
          public class skeletonStrategy: Strategy
          {
                 private DataSeries myData; 
      
                  protected override void OnBarUpdate()
                  {
                        // Lots of stuff 
                        
                        myData= new DataSeries(this,MaximumBarsLookBack.Infinite);
      
                        for (int i = 0; i < lookbackLength; i++)
                        {
                              int j = getClosePriceOfInterest(i); 
                              double x = getScaleFactor(i); 
                              myData.Set(lookbackLength-i,Close[j]*x); 
                         }
                  }
            }
      }
      The big idea is that I am constructing an alternative DataSeries. The lookbackLength changes, and I am "reversing" the order of the bars in the alternative DataSeries (so I cannot save off the prior values from the last OnBarUpdate). This need to be done every OnBarUpdate loop.

      Do I need to do this differently? I would like to do something like Dispose(myData) at the end of the loop - preferably clean up myData before OnTermination would get to it.

      Since I am calling new DataSeries, I think this is IDisposable, which means I should Dispose in OnTermination. But, doesn't OnTermination get called at termination? I would like to clean up my mess before this - right away, actually.

      Does any of this make sense?

      Comment


        #4
        Ummmm, that doesn't look cool.

        What is lookbackLength set to?

        There is an old post I need to find...

        Koganam will probably have an answer first though.

        Originally posted by Serac View Post
        @sledge: Sure thing. Thanks for the reply. Below is a skeleton:

        Code:
        namespace NinjaTrader.Strategy
        {
            public class skeletonStrategy: Strategy
            {
                   private DataSeries myData; 
        
                    protected override void OnBarUpdate()
                    {
                          // Lots of stuff 
                          
                          myData= new DataSeries(this,MaximumBarsLookBack.Infinite);
        
                          for (int i = 0; i < lookbackLength; i++)
                          {
                                int j = getClosePriceOfInterest(i); 
                                double x = getScaleFactor(i); 
                                myData.Set(lookbackLength-i,Close[j]*x); 
                           }
                    }
              }
        }
        The big idea is that I am constructing an alternative DataSeries. The lookbackLength changes, and I am "reversing" the order of the bars in the alternative DataSeries (so I cannot save off the prior values from the last OnBarUpdate). This need to be done every OnBarUpdate loop.

        Do I need to do this differently? I would like to do something like Dispose(myData) at the end of the loop - preferably clean up myData before OnTermination would get to it.

        Since I am calling new DataSeries, I think this is IDisposable, which means I should Dispose in OnTermination. But, doesn't OnTermination get called at termination? I would like to clean up my mess before this - right away, actually.

        Does any of this make sense?

        Comment


          #5
          This is the post that come to mind:






          Originally posted by Serac View Post
          @sledge: Sure thing. Thanks for the reply. Below is a skeleton:

          Code:
          namespace NinjaTrader.Strategy
          {
              public class skeletonStrategy: Strategy
              {
                     private DataSeries myData; 
          
                      protected override void OnBarUpdate()
                      {
                            // Lots of stuff 
                            
                            myData= new DataSeries(this,MaximumBarsLookBack.Infinite);
          
                            for (int i = 0; i < lookbackLength; i++)
                            {
                                  int j = getClosePriceOfInterest(i); 
                                  double x = getScaleFactor(i); 
                                  myData.Set(lookbackLength-i,Close[j]*x); 
                             }
                      }
                }
          }
          The big idea is that I am constructing an alternative DataSeries. The lookbackLength changes, and I am "reversing" the order of the bars in the alternative DataSeries (so I cannot save off the prior values from the last OnBarUpdate). This need to be done every OnBarUpdate loop.

          Do I need to do this differently? I would like to do something like Dispose(myData) at the end of the loop - preferably clean up myData before OnTermination would get to it.

          Since I am calling new DataSeries, I think this is IDisposable, which means I should Dispose in OnTermination. But, doesn't OnTermination get called at termination? I would like to clean up my mess before this - right away, actually.

          Does any of this make sense?

          Comment


            #6
            Thanks, Sledge.

            That is an interesting thread. I am going to have to carefully go over it tomorrow (it is late).

            I haven't got to the point where I am making sure the new DataSeries make sense. At this point, I am seeing if I can come up with a viable implementation. This whole OOP thing is new to me.

            The lookbackLength variable varies - it has no preset length. More background: the new DataSeries is the input DataSeries, only with with the order backwards. This means that I need to update the new DataSeries each new bar (either by rewriting it or shifting it - either way requires a loop, I think). The value of lookbackLength determines how far I go back.

            I think the issue is how to manage garbage collection. C# is so managed, I feel that my hands are tied.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by PaulMohn, Today, 05:00 AM
            0 responses
            8 views
            0 likes
            Last Post PaulMohn  
            Started by ZenCortexAuCost, Today, 04:24 AM
            0 responses
            6 views
            0 likes
            Last Post ZenCortexAuCost  
            Started by ZenCortexAuCost, Today, 04:22 AM
            0 responses
            3 views
            0 likes
            Last Post ZenCortexAuCost  
            Started by SantoshXX, Today, 03:09 AM
            0 responses
            16 views
            0 likes
            Last Post SantoshXX  
            Started by DanielTynera, Today, 01:14 AM
            0 responses
            5 views
            0 likes
            Last Post DanielTynera  
            Working...
            X