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 usazencort, Today, 01:16 AM
          0 responses
          1 view
          0 likes
          Last Post usazencort  
          Started by kaywai, 09-01-2023, 08:44 PM
          5 responses
          603 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          6 responses
          22 views
          0 likes
          Last Post xiinteractive  
          Started by Pattontje, Yesterday, 02:10 PM
          2 responses
          21 views
          0 likes
          Last Post Pattontje  
          Started by flybuzz, 04-21-2024, 04:07 PM
          17 responses
          230 views
          0 likes
          Last Post TradingLoss  
          Working...
          X