Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Brandon H.NinjaTrader Customer Service

    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 Jimmyk, 01-26-2018, 05:19 AM
      6 responses
      835 views
      0 likes
      Last Post emuns
      by emuns
       
      Started by jxs_xrj, 01-12-2020, 09:49 AM
      6 responses
      3,291 views
      1 like
      Last Post jgualdronc  
      Started by Touch-Ups, Today, 10:36 AM
      0 responses
      10 views
      0 likes
      Last Post Touch-Ups  
      Started by geddyisodin, 04-25-2024, 05:20 AM
      11 responses
      62 views
      0 likes
      Last Post halgo_boulder  
      Started by Option Whisperer, Today, 09:55 AM
      0 responses
      9 views
      0 likes
      Last Post Option Whisperer  
      Working...
      X