Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    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 trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        22 views
        0 likes
        Last Post trilliantrader  
        Started by Davidtowleii, Today, 12:15 AM
        0 responses
        3 views
        0 likes
        Last Post Davidtowleii  
        Started by guillembm, Yesterday, 11:25 AM
        2 responses
        9 views
        0 likes
        Last Post guillembm  
        Started by junkone, 04-21-2024, 07:17 AM
        9 responses
        68 views
        0 likes
        Last Post jeronymite  
        Started by mgco4you, Yesterday, 09:46 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X