Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Drawing a line

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

    #16
    Hello kiro1000,

    Thanks for that information.

    I have tested the script you shared and when adding the indicator to the chart, we can see an error appearing in the Log tab of the Control Center.

    The error message states "Indicator 'OneLine': 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."

    This error message indicates 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 CurrentBar check could be used in your indicator's logic to ensure that a certain number of bars have been processed before the indicator begins calculation. A CurrentBar check would look something like this.

    Code:
    if (CurrentBar < 10)
        return;
    This would check to make sure that 10 bars have been processed before the indicator begins its calculations.

    After adding a CurrentBar check to the indicator script you shared, I see the indicator is drawing the line on the chart. See the attached screenshot.

    See the help guide documentation below for more information and sample code.

    CurrentBar - https://ninjatrader.com/support/help...currentbar.htm
    Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm​​
    Attached Files
    <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


      #17
      Hello Brandon,

      I want to express my gratitude to you and Chelsea for your detailed analysis and valuable assistance. Your guidance has been instrumental in resolving the issue. I carefully reviewed the error message, incorporated a CurrentBar check into the indicator script, and I'm pleased to report that the line is now being drawn correctly on the chart.

      I truly appreciate your support and the attached screenshot, which provided clarity throughout the troubleshooting process.

      It works!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      578 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      334 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X