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 Hwop38, 05-04-2026, 07:02 PM
      0 responses
      181 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      334 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      258 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      358 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      187 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X