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 trilliantrader, 04-18-2024, 08:16 AM
      4 responses
      18 views
      0 likes
      Last Post trilliantrader  
      Started by mgco4you, Today, 09:46 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by wzgy0920, Today, 09:53 PM
      0 responses
      9 views
      0 likes
      Last Post wzgy0920  
      Started by Rapine Heihei, Today, 08:19 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by Rapine Heihei, Today, 08:25 PM
      0 responses
      10 views
      0 likes
      Last Post Rapine Heihei  
      Working...
      X