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 NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      56 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      133 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      73 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X