Announcement

Collapse
No announcement yet.

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.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Awesome, thanks

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      90 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      137 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      120 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      72 views
      0 likes
      Last Post PaulMohn  
      Working...
      X