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 cmoran13, 04-16-2026, 01:02 PM
      0 responses
      46 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      28 views
      0 likes
      Last Post PaulMohn  
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      163 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      98 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      158 views
      2 likes
      Last Post CaptainJack  
      Working...
      X