Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing plots

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

    Accessing plots

    Hi folks-

    I have an indicator that plots the percent change in price from current day open on three instruments -- found the code on YouTube and modified it for my purposes. These instruments are each added to the indicator via a one tick series. The calculated values plot as desired, as well as a summation of the calculated plots.

    However, when I try to access these plots through another indicator (like trying to take an HMA of the one of the plots), either through an indicator or a strategy, I get the following errors:
    • Indicator 'PCsum2' (the name of the custom indicator): Error on calling 'OnBar'Update' method on bar 20: Index was outside the bounds of the array.
    • Indicator 'HMA' (trying to take an HMA of one of the plots): Error on calling 'OnBar'Update' method on bar 1: You are accessing an index with a value that is invalid since it is out-of-range.
    • Indicator 'WMA' (not sure why this shows up, I'm using an HMA...): Error on calling 'OnBar'Update' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range.
    When I try to do this inside a strategy, I get similar error messages but sometimes with really high bar numbers in the thousands.

    Attached is the indicator code. Can anyone point me in the right direction?

    Many thanks!
    Attached Files

    #2
    Hello andersonbd,

    Thanks for your post.

    These error messages indicate that you are trying to access a BarsAgo value that is not valid. A more simple example using one series would be on bar 5 you check for 6 BarsAgo. There are not yet 6 bars so the CurrentBar minus 6 would be a negative number or a non-existent bar.

    A CurrentBars check could be used in your indicator's logic to ensure that a certain number of bars have processed before the indicator begins calculation.

    In the script you shared I see you have a CurrentBars check for the added series but not for the primary series the script is running on. A CurrentBars check would need to be added to the script to check if the primary series has enough bars.

    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

    Indexing errors can also occur when using an invalid index with arrays or collections. Below is a forum thread with a publicly available link to 3rd party educational site on arrays and index out of range errors.

    https://forum.ninjatrader.com/forum/...1050092​
    <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
      Got it, thanks Brandon!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      637 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      366 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      107 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      569 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      572 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X