• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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.

            http://www.ninjatrader.com/support/h...rslookback.htm

            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.
                Patrick H.NinjaTrader Customer Service

                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.
                    Patrick H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by uiwislth, Yesterday, 11:25 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post uiwislth  
                    Started by Steve L, Yesterday, 10:04 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post Steve L
                    by Steve L
                     
                    Started by marianfed, Yesterday, 09:47 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post marianfed  
                    Started by hir04068, Yesterday, 09:29 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post hir04068  
                    Started by iq200, 03-11-2018, 07:49 PM
                    24 responses
                    1,017 views
                    0 likes
                    Last Post mrlucky1x  
                    Working...
                    X