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 StockTrader88, 03-06-2021, 08:58 AM
      45 responses
      3,992 views
      3 likes
      Last Post johntraderuser2  
      Started by TAJTrades, Today, 09:46 AM
      0 responses
      7 views
      0 likes
      Last Post TAJTrades  
      Started by rhyminkevin, Yesterday, 04:58 PM
      5 responses
      62 views
      0 likes
      Last Post dp8282
      by dp8282
       
      Started by realblubb, Today, 09:28 AM
      0 responses
      8 views
      0 likes
      Last Post realblubb  
      Started by AaronKoRn, Yesterday, 09:49 PM
      1 response
      19 views
      0 likes
      Last Post Rikazkhan007  
      Working...
      X