Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error with Draw.Ray Help Please

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

    Error with Draw.Ray Help Please

    Whenever I use this Draw.Ray(NinjaScriptBase owner, string tag, int startBarsAgo, double startY, int endBarsAgo, double endY, bool isGlobal, string templateName)

    I get the following error:

    Unhanded Exception: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

    Please let me know what could be causing it.

    I have even tried a different function:
    Draw.Ray(this,"test",0,136,1,137,Brushes.Red);
    Something that simple causes my error as well.
    This all happened since the most recent version of NT8

    #2
    Hello trader3419,

    Without the full code I’m unable to test on my end. Furthermore, debugging customer code is out of the scope of NinjaScript support. However, if you’d like I could have someone from our business development team pass over a list of third party developers that you could contact about debugging your code. If that is the case, please send me an email to platformsupport[at]ninjatrader[dot]com with the text "ATTN Jim" and this thread's URL.

    I’ve provided some links which you may find helpful on debugging.

    Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

    TraceOrders: http://ninjatrader.com/support/forum...ead.php?t=3627

    Indexing issues: http://ninjatrader.com/support/forum...ead.php?t=3170

    Comment


      #3
      Can you at least tell me what would cause Draw.Ray to throw that type of error?

      Comment


        #4
        Hello trader3419,

        The Indexing issues link covers some issues seen like the error you are reporting.

        It could be, for example, that on the first bar formation, OnBarUpdate() will call Draw.Ray(this,"test",0,136,1,137,Brushes.Red); As it is referencing the an ending point as the previous bar, it will not have any knowledge of this bar because a "previous" bar has not been created yet.

        An issue like this could be corrected with a return condition that checks for enough bars:

        Code:
        if (CurrentBars < 1)
        	return;

        Comment


          #5
          My code draws the ray after a mouse click. There are enough bars.
          Any other ideas?

          Comment


            #6
            Without the full code and only knowing the issue you are experiencing is an indexing error, I cannot provide much more input.

            You could try placing a Print() statement that prints the price data for the barsAgo that you are referencing in the Draw.Ray() call.

            You may additionally wish to use IsValidDataPoint() to verify that the data points are valid before referencing.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            601 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            347 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            559 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            558 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X