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 Aviram Y, Today, 05:29 AM
        3 responses
        10 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by algospoke, 04-17-2024, 06:40 PM
        3 responses
        26 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by bmartz, 03-12-2024, 06:12 AM
        3 responses
        30 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by gentlebenthebear, Today, 01:30 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by cls71, Today, 04:45 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X