Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on calling "OnBarUpdate"

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

    Error on calling "OnBarUpdate"

    Hi,

    I've been trying to convert my NT7 indicators to NT8 in recent months. And the most common error I'm getting is "Error on calling 'OnBarUpdate' and the reasons are as follows:-

    1. Sequence has no elements.
    2. You are accessing an index with a value that is invalid since it is out of range. I.E accessing a series [barsAgo] with a value of 5 when there are only 4 bars

    These reasons or errors never occurred in NT7 but are only having them in NT8. I have a if(CurrentBar is < x) return, and it's a pretty generous x, yet I'm still seeing the error for reasons I can't fathom. Fortunately for my key indicator, NT support was able to help as they did the conversion as it was available in the NT7 library. I wouldn't even know where to begin where there were over a thousand lines of code.

    Could someone please help with explaining why these issues are cropping up? There are no issues with any of the indicators and it continues printing as per normal. Just that when you're about to logoff for the day and you look at your Control Center and you see the Error line.

    Regards
    Kay Wai

    #2
    Sure, let's just go ask the mechanic why your old sports
    car isn't working well -- but instead of taking that car to
    the mechanic so he can look at it -- you ride your motor
    cycle instead.

    What's the first thing the mechanic will probably say
    to you?

    "Bring the car in so I can take a look."

    -=o=-

    Any chance you can upload some code?

    I mean, without taking a look at your code, esp the code
    in your OnBarUpdate -- it's a whole lot of guessing -- and
    ace mechanics don't like to waste their time with guessing.

    The error message is just a clue.
    The answer is in the code.

    Just my 2˘.

    Comment


      #3
      Hi bltdavid,

      I've attached an indicator that I recently converted from NT7 to NT8 and am currently trying to change it from an OnBarClose calculation to an OnPriceChange calculation.

      The error on calling 'OnBarUpdate' seems to be more pronounced on Weekly and Monthly bars than on intraday bars even though I allow for 10 years of data on the weeklies and monthlies.

      Hope you can help. Thanks.

      Kay Wai
      Attached Files
      Last edited by kaywai; 01-08-2022, 11:25 PM.

      Comment


        #4
        Thanks for attaching your code.

        Interestingly, it might be useful to also see the original NT7 code.
        Why do I say that?

        Well, because of some oddities with the local variables in your
        OnBarUpdate. For example, let's take a look at Asum.

        Asum is one of many local variables, and upon each call to
        OnBarUpdate, Asum and the other local variables are all brand
        new, meaning they are all set to zero by the initialization in their
        declaration, and thus each new Asum variable has no relationship
        with any past Asum value from any previous calls to OnBarUpdate.

        Is that how the original NT7 code was organized?

        I mean, I see this in your attached code,

        Code:
        if ((((Math.Max(Close[1],High[0])) >= (Math.Min(Close[6],Low[5]))) || ((Math.Max(Close[1],High[0])) >= (Math.Min(Close[7],Low[6]))))
        && (((Math.Min(Close[1],Low[0])) <= (Math.Max(Close[6],High[5]))) || ((Math.Min(Close[1],Low[0])) <= (Math.Max(Close[7],High[6]))))||
           (((Math.Max(Close[3],High[2])) >= Close[7]) || (Math.Max(Close[3],High[2]) >= Close[8]))
        && ((Math.Min(Close[3],Low[2]) <= Close[7]) || (Math.Min(Close[3],Low[2]) <= Close[8])))
        {
             Asum [COLOR=#e74c3c][B]+= [/B][/COLOR](AHighRei + ALowRei);
        }
        else
        {
             Asum = 0;
        }
        See that += operator in red?
        What the heck is being accumulated? I don't see any loops, the
        Asum variable is local, so you're not retaining previous values from
        prior calls to OnBarUpdate ... so why all the += operators?

        My conjecture regarding the uselessness of the += may be a
        red herring, but it's hard to know without seeing the original code.

        Can you attach the original NT7 code you started with?

        Comment


          #5
          Hi bltdavid,

          Please see attached.

          Essentially all 5 variables - ASum to ESum - are recalculated at OnBarUpdate. Each new ASum has no relationship on any past ASum BUT
          ASum becomes BSum, BSum becomes CSum etc etc.

          Thx.

          Kay Wai
          Attached Files
          Last edited by kaywai; 01-09-2022, 11:44 AM.

          Comment


            #6
            Hello kaywai,

            Any index used must be larger than the size of the collection.

            Below is a link to a forum post on indexing errors.
            Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:


            I would recommend starting by identifying the line and exact index that is invalid.

            Add a print before each line that uses an index that prints a label for that index. What print is the last print to appear? What is the line of code below that print?

            Below is a link to a forum post that demonstrates using prints to understand behavior.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            574 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            332 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X