Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on calling 'OnBarUpdate' method on bar

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

    Error on calling 'OnBarUpdate' method on bar

    Hi.

    Getting an error
    Error on calling 'OnBarUpdate' method on bar 6924: 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 on the chart.
    when trying to run my strategy.

    My strategy compares the previous SwingHighBar instance to a past instance.
    Code:
    (Close[mySwing1.SwingHighBar(0, 1, 50)] < (Close[mySwing1.SwingHighBar(0, 2, 50)])
    This error pops up when I change my swing strength from 1 to 3+.

    Under OnBarUpdate, i have
    Code:
     if (CurrentBars[0] < 50)
    return;
    Im stuck on what to change to make this work.

    Thanks!

    #2
    Hello Ousher,

    Thanks for your post.

    When checking for the SwingHighBar you should test if it returns a -1 value indicating, it was not found.

    Reference: https://ninjatrader.com/support/help...nt8/?swing.htm

    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello Ousher,

      Thanks for your post.

      When checking for the SwingHighBar you should test if it returns a -1 value indicating, it was not found.

      Reference: https://ninjatrader.com/support/help...nt8/?swing.htm
      Hi, can you explain in more detail on how to test if it returns the value?

      Comment


        #4
        Hello Ousher,

        Thanks for your reply.

        Here is an example relative to yours.

        if (mySwing1.SwingHighBar(0, 2, 50) != -1 && mySwing1.SwingHighBar(0, 1, 50) != -1) // if they are not equal to -1 then perform the check
        {
        (Close[mySwing1.SwingHighBar(0, 1, 50)] < (Close[mySwing1.SwingHighBar(0, 2, 50)])
        }

        Comment


          #5
          Originally posted by NinjaTrader_PaulH View Post
          Hello Ousher,

          Thanks for your reply.

          Here is an example relative to yours.

          if (mySwing1.SwingHighBar(0, 2, 50) != -1 && mySwing1.SwingHighBar(0, 1, 50) != -1) // if they are not equal to -1 then perform the check
          {
          (Close[mySwing1.SwingHighBar(0, 1, 50)] < (Close[mySwing1.SwingHighBar(0, 2, 50)])
          }
          Got it, thanks!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          47 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          23 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          33 views
          1 like
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          51 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          42 views
          0 likes
          Last Post CarlTrading  
          Working...
          X