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

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

    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)])
        }
        Paul H.NinjaTrader Customer Service

        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 WHICKED, Today, 12:45 PM
          2 responses
          18 views
          0 likes
          Last Post WHICKED
          by WHICKED
           
          Started by GussJ, 03-04-2020, 03:11 PM
          15 responses
          3,274 views
          0 likes
          Last Post xiinteractive  
          Started by Tim-c, Today, 02:10 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Taddypole, Today, 02:47 PM
          0 responses
          3 views
          0 likes
          Last Post Taddypole  
          Started by chbruno, 04-24-2024, 04:10 PM
          4 responses
          51 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Working...
          X