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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      47 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      23 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      51 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X