Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Could Draw.Line() be used in for() {} sentence?

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

    Could Draw.Line() be used in for() {} sentence?

    I have a list of ZigZagLine as below. The list has StartBarNumber; EndBarNumber, StartValue, EndValue. I tried to use Draw.Line() to draw lines between these points. but the result only show the last line.

    How to fix my code?




    --------------------------------------------------------------------------------------------------------------------------------------------------------------

    public struct ZigZagLine
    {
    public int StartBarNumber;
    public int EndBarNumber;
    public double StartValue;
    public double EndValue;
    }

    List<ZigZagLine> ZigZagLines = new List<ZigZagLine>();

    for (int j = 0; j < ZigZagLines.Count; ++j)
    {
    Draw.Line(this, "j", true, ChartBars.Count-ZigZagLines[j].StartBarNumber, ZigZagLines[j].StartValue, ChartBars.Count - ZigZagLines[j].EndBarNumber, ZigZagLines[j].EndValue, Brushes.Blue, DashStyleHelper.Solid, 5);
    }


    #2
    Hello LadGta2018,

    Thanks for your post.

    All draw objects must have a unique tag name to remain on the chart. When the same tag name is used, the previously draw object is automatically removed when the new object is created.

    A common approach to showing all draw objects is to append CurrentBar to the chosen tag name. CurrentBar is the system bar counter so for each bar you would have a unique number. In your example this would look like:

    Draw.Line(this, "j"+CurrentBar, true, ChartBars.Count-ZigZagLines[j].StartBarNumber, ZigZagLines[j].StartValue, ChartBars.Count - ZigZagLines[j].EndBarNumber, ZigZagLines[j].EndValue, Brushes.Blue, DashStyleHelper.Solid, 5);

    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello LadGta2018,

      Thanks for your post.

      All draw objects must have a unique tag name to remain on the chart. When the same tag name is used, the previously draw object is automatically removed when the new object is created.

      A common approach to showing all draw objects is to append CurrentBar to the chosen tag name. CurrentBar is the system bar counter so for each bar you would have a unique number. In your example this would look like:

      Draw.Line(this, "j"+CurrentBar, true, ChartBars.Count-ZigZagLines[j].StartBarNumber, ZigZagLines[j].StartValue, ChartBars.Count - ZigZagLines[j].EndBarNumber, ZigZagLines[j].EndValue, Brushes.Blue, DashStyleHelper.Solid, 5);
      Thanks for quick response.

      Is there any other way to give a different tag name except use CurrentBar?

      My second question is "j" is already a different name since j is keep changing in "for" . j will be 0, then 1, then 2, then 3.............

      Comment


        #4
        Hello LadGta2018,

        Thanks for your reply.

        In your example the tag name is "j" which is a string. To use the integer counter j you would have to use j.ToString() which will convert the numerical value of the integer variable j to a string which is what the tag name field requires.

        Comment


          #5
          Originally posted by NinjaTrader_PaulH View Post
          Hello LadGta2018,

          Thanks for your reply.

          In your example the tag name is "j" which is a string. To use the integer counter j you would have to use j.ToString() which will convert the numerical value of the integer variable j to a string which is what the tag name field requires.
          Thanks, that works well!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          640 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          366 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          107 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          569 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          572 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X