Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DrawLine problem

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

    DrawLine problem

    Hi everyone

    If I try this code:

    DrawLine("line 0", true, 2, 1.0521, 0, 1.0521, Color.Black, DashStyle.Solid, 5);

    it doesn't draw and I get this error message:

    "Error calling 'OnBarUpdate' ... on bar 0: ... startBarsAgo out of valid range 0 though 0, was 2."
    But if I try this:

    DrawLine("line 0", true, 0, 1.0521, -2, 1.0521, Color.Black, DashStyle.Solid, 5);

    it works!

    Isn't it possible to draw a line from a few bars to the left to bar[0] or what am I doing wrong?

    Many thanks in advance.

    #2
    Hello,

    Thank you for the question.

    You can draw in the past but only if the bars are available to draw on.

    In the error you can see that this occurred on the bar 0, so what your DrawLine statement is saying is to draw a line from 2 bars ago to 0 bars ago. This would come out to bars -2 and 0 on bar 0 which would cause an error because there will never be a bar less than 0.

    To correct this you need to ensure you start drawing this only after 2 bars are available or by using the following:

    Code:
    if(CurrentBar < 2) return;
    This stops the OnBarUpdate from running until 2 bars are available and the code should work.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks very much, Jesse. That works a treat!

      I wouldn't have thought that was necessary for drawing a line, but it is. The same logic obviously works here as with indicators, when you have to allow for enough bars to paint.

      Cheers,

      Ed

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by wzgy0920, 04-20-2024, 06:09 PM
      2 responses
      26 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, 02-22-2024, 01:11 AM
      5 responses
      32 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, Yesterday, 09:53 PM
      2 responses
      49 views
      0 likes
      Last Post wzgy0920  
      Started by Kensonprib, 04-28-2021, 10:11 AM
      5 responses
      192 views
      0 likes
      Last Post Hasadafa  
      Started by GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,235 views
      0 likes
      Last Post xiinteractive  
      Working...
      X