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

Looking up previous RSI and Stochastic values

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

    Looking up previous RSI and Stochastic values

    Hello,

    This might be an easy one but I am having the hardest time figuring this one out. I am capturing the RSI and Stochastic values for the current bar (which works perfectly) but when I try to capture it for a previous bar I am getting the following error:

    "Error on calling 'OnBarUpdate' method on bar 0: 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."

    Any ideas on how to fix this?

    Kenson

    #2
    Hello Kensonprib,

    Thank you for your post.

    This error message indicates that you are trying to access a BarsAgo value in your script that has not yet processed.

    As one example, calling Close[1] when CurrentBar is 0 (the very first bar) will cause this error. The reason for this is because there will not be a bar ago; essentially there is not enough data at bar 0 to look back one bar.

    A CurrentBar check should be added to your script to ensure that there are enough bars processed for the BarsAgo value you are accessing. If you have multiple data series added in your script, you would need to use a CurrentBars check. See the example of a CurrentBar check below.

    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


      #3
      Awesome, thanks

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by jclose, Today, 09:37 PM
      0 responses
      4 views
      0 likes
      Last Post jclose
      by jclose
       
      Started by WeyldFalcon, 08-07-2020, 06:13 AM
      10 responses
      1,413 views
      0 likes
      Last Post Traderontheroad  
      Started by firefoxforum12, Today, 08:53 PM
      0 responses
      9 views
      0 likes
      Last Post firefoxforum12  
      Started by stafe, Today, 08:34 PM
      0 responses
      10 views
      0 likes
      Last Post stafe
      by stafe
       
      Started by sastrades, 01-31-2024, 10:19 PM
      11 responses
      169 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X