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

Best practice to check series bounds?

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

    Best practice to check series bounds?

    What is the best practice to avoid constantly getting crashes from indexing into a series (say an indicator value in the past) that doesn't yet exist?

    Thanks

    #2
    Best practice?

    Well, first things first,
    Add some guard at the start of your OnBarUpdate,

    Code:
    if (CurrentBar < 10)
        return;
    Where 10 represents the maximum number of past
    bars you'll ever need to look at. That value '10' could
    smaller or larger, it just depends on your logic.

    This kind of guard code should fix the vast majority
    of issues when looking at past bars.

    [If you have additional data series, there are other
    checks they may need to be done.]

    Just my 2˘.

    Comment


      #3
      Hello joejoeagogo,

      Thanks for your post.

      bltdavid is correct.

      A CurrentBar check could be used in your script's logic to ensure that a certain number of bars have been processed before the script begins calculation. A CurrentBar check would look something like this.

      Code:
      if (CurrentBar < 10)
          return;
      This would check to make sure that 10 bars have processed before the script begins its calculations.

      See the help guide documentation below for more information.
      CurrentBar - https://ninjatrader.com/support/help...currentbar.htm
      CurrentBars - https://ninjatrader.com/support/help...urrentbars.htm
      Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm

      Let us know if we may assist further.
      Brandon H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by GLFX005, Today, 03:23 AM
      0 responses
      1 view
      0 likes
      Last Post GLFX005
      by GLFX005
       
      Started by XXtrader, Yesterday, 11:30 PM
      2 responses
      11 views
      0 likes
      Last Post XXtrader  
      Started by Waxavi, Today, 02:10 AM
      0 responses
      6 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Started by TradeForge, Today, 02:09 AM
      0 responses
      14 views
      0 likes
      Last Post TradeForge  
      Started by Waxavi, Today, 02:00 AM
      0 responses
      3 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Working...
      X