Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Understanding Draw.Line()

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

    Understanding Draw.Line()

    I am attempting to draw a line in my script but it produces and error and I am assuming one of the parameters is incorrect. I get the error
    "ndicator 'Amaterasu': Error on calling 'OnBarUpdate' method on bar 19: You are accessing an index with a value that is invalid since it is out-of-range.

    code: Draw.Line(this, @"AmaterasuShort"+Bars.Count.ToString(), false, 0, High[1], Bars.Count + 100, High[1], "Susanoo_6_Short");

    I can successfully draw other objects like text or up/down triangle with the current logic but trying to draw line causes the error. I am a bit confused on the parameter "endBarsAgo" maybe even "startBarsAgo"

    Are there any examples you can point me to.

    #2
    Hello Itachi,

    The StartBarsAgo is how many bars ago the line starts drawing from the EndBarsAgo is where the line ends. These are the anchor points, which are anchored to a bar and time.

    As an example you are using the High from 1 bar ago with the index [1].

    If you wanted to draw a line from the previous bar to the current bar at the price of the High from the previous bar, this would appear as:

    Draw.Line(this, @"AmaterasuShort"+Bars.Count.ToString(), false, 1, High[1], 0, High[1], "Susanoo_6_Short");

    The Bars.Count is the total number of bars, which is always greater than CurrentBar. I would not be possible to draw something more bars ago than there bars on the chart.

    For whatever barsAgo values you choose, there needs to be than many bars processed, meaning CurrentBar must be greater than any barsAgo index.

    If I wanted to draw from 10 barsAgo to 5 barsAgo, I would need to ensure there are at least 10 bars.

    if (CurrentBar < 10)
    return;

    Draw.Line(this, "MyLine" + CurrentBar, true, 10, High[10], 5, High[5], Brushes.Blue);

    Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Actually I am trying to mark off a level looking forward. So when my criteria is met on current bar the line begins on the current bar and will be of a certain length.

      Comment


        #4
        Hello Itachi,

        The Currently updating bar CurrentBar, is the last bar.

        Are you wanting to draw out in the blank space to the right of the chart bars?

        If so, you will not be able to use a Draw method to do that. You will need to custom render it in OnRender().


        Included with NinjaTrader is the SampleCustomRender indicator which demonstrates custom rendering.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          yes that is what I was trying to do

          Comment


            #6
            Hello Itachi,

            This example might be helpful for finding the x value of the last bar on the chart.


            Then you will need to decide how far to the right of that you want to render your custom line.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            630 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            364 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            566 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            568 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X