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

OnBarUpdate and barsAgo

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

    OnBarUpdate and barsAgo

    Hi there,

    I have an indicator that counts previous bars that are in different stages.

    I found when switching instruments this morning I get an error with barsAgo.

    Error on calling 'OnBarUpdate' method for indicator 'itStageMTF' on bar 10209: barsAgo needed to be between 0 and 255 but was 278

    What barsAgo is this referring to? Is there a way I can reset it to begin from zero at a certain point?

    Thanks.

    #2
    Hello ij001,

    barsAgo, is referring to the bracket '[]' method used to get values from previous bars of data.

    It sounds like the indicator maybe using a variable to look back a certain bar which maybe causing this issue.

    Did you create this indicator or was this one that was downloaded?
    JCNinjaTrader Customer Service

    Comment


      #3
      I created it. It is just a number of StringSeries that count bars of various lengths.

      I don't know the number of bars so I can't use CountIf.

      Anyway would a snippet of code reset barsAgo?

      I currently use

      if (CurrentBar == 0)

      to set all of my StringSeries to 0

      Comment


        #4
        Hello ij001,

        I do not believe it is going to be the resetting the "barsAgo" but it sounds like you have your "MaximumBarsLookBack" set to 256 but you are trying to access values more than that.

        Have you tried changing it to Infinite?

        Code:
        protected override void Initialize() 
        {
            // Store all series values instead of only the last 256 values
            MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
        }
        JCNinjaTrader Customer Service

        Comment


          #5
          Thanks I will try that. Will it cause any issues with how fast the indicator may run?

          Comment


            #6
            Hello ij001,

            It will cause your Indicator to use up more memory since by default NinjaTrader only keeps 256 objects for Series like DataSeries and StringSeries, but by how much is going to depend on how much Historical Data that you are loading.



            If that resolves your issue but uses up to much memory then you may want to add a check to make sure that you are not accessing back more than 255 in your Series objects.
            JCNinjaTrader Customer Service

            Comment


              #7
              Not to revive an old thread, but I'm having the same issue but kind of in a catch 22. I have a low frequency scalping strategy that needs 20 second bars. Some of the indicator look back ranges are 3,000 bars or so. But if i set MaximumBarsLookBack.Infinite then the Ninjatrader.sdf database becomes huge, I get errors associated with that and NT barely runs. Without amending the strategies much, any ideas on how to fix this catch 22? Thanks.

              Comment


                #8
                Hello dirkdiggler,

                Thank you for your post.

                There is no means around this. You may wish to consider debugging the code further to see what other events are causing the database to grow is size.

                We have additional information on debugging at the following link: http://ninjatrader.com/support/forum...ead.php?t=3418

                Please let me know if you have any questions.

                Comment


                  #9
                  I think the database is growing because the strategies are using an unmanaged approach with COBC=false, and it updates the stops/orders on every single bar. On small bar intervals such as 20 second bars this appears to make the db grow very rapidly. I know restarting Ninja will clear it, but is there any code that can be added to prevent the database from hitting its maximum size of ~256MB ?

                  Comment


                    #10
                    Hello dirkdiggler,

                    Thank you for your response.

                    There is nothing specific to the database in code.

                    Please let me know if you have any questions.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Kaledus, Today, 01:29 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post Kaledus
                    by Kaledus
                     
                    Started by PaulMohn, Today, 12:36 PM
                    1 response
                    16 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by yertle, Yesterday, 08:38 AM
                    8 responses
                    37 views
                    0 likes
                    Last Post ryjoga
                    by ryjoga
                     
                    Started by rdtdale, Today, 01:02 PM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by alifarahani, Today, 09:40 AM
                    3 responses
                    19 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X