Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get ChartHorizontalLie color propierty

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

    Get ChartHorizontalLie color propierty

    Hi

    How can I get the line's color in the chart?

    I do:

    foreach (ChartObject CO in this.ChartControl.ChartObjects)
    {
    if (CO is NinjaTrader.Gui.Chart.ChartHorizontalLine)
    {
    }
    }

    But I can't get the Color Property.

    Best Regards
    David

    #2
    Hello,

    If you are trying to access a drawing object from script I will provide an example below.

    You need to cast the object as the correct type to get its Pen property, there is not a Color property for any of the drawing objects as they use Pens. The color is in turn defined in the pen along with other parameters for the lines style.

    Code:
    foreach (IDrawObject draw in DrawObjects)
    {
    	if(draw.DrawType == DrawType.HorizontalLine)
    	{
    		IHorizontalLine hLine = draw as IHorizontalLine;	
    		Print(hLine.Pen.Color.ToString());
    		if(hLine.Pen.Color == Color.Blue)
    			hLine.Pen.Color = Color.Red;
    	}
    }
    For all of the drawing object types, they basically all just start with a capital I, or IRay, IHorizontalLine, etc...

    If you do not cast the object to the correct type of object that it is, you will be missing the additional drawing object specific properties from the options that you are presented with.

    Please let me know if I may be of additional assistance.

    Comment


      #3
      Hi David,

      Here is a similar approach if you decide to use unsupported methods:


      foreach (ChartObject CO in this.ChartControl.ChartObjects) {
      ChartHorizontalLine line = CO as ChartHorizontalLine;
      Color lineColor;
      if (line != null) lineColor = line.Pen.Color;
      }
      Last edited by ninZa; 01-27-2015, 11:06 PM.
      ninZa
      NinjaTrader Ecosystem Vendor - ninZa.co

      Comment


        #4
        Hi David,

        I have edited my answer. The correct use is: line.Pen.Color

        Cheers.
        Pi
        ninZa
        NinjaTrader Ecosystem Vendor - ninZa.co

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        579 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X