Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

User Definable Color Inputs

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

    User Definable Color Inputs

    Applies to NinjaTrader 7

    User definable inputs do not need to be limited to numeric values. You can have colors as an input as well. To do this you will need to make a public property for a Color object instead of an int or double.

    In the "Properties" region of your code, there is only a slight change in the code snippet you would normally use to create user definable inputs. You need an extra line above the Description field.
    Code:
    [COLOR=Red][XmlIgnore()][/COLOR]
    [Description("Color for painted region")]
    [GridCategory("Parameters")]
    The second difference is in the next line of code:
    Code:
    public [COLOR=red]Color[/COLOR] PaintColor
    {
         get { return paintColor; }
         set { paintColor = value; }
    }
    This creates a color input for use in the dialog window when we try to add the NinjaScript to a chart.

    Some additional extra code that is required for creating a color input is to serialize the color. Serialization is necessary for NinjaTrader to use the color input throughout the program. Please note that serialization is a general concept not exclusive to color inputs. There may be other struct/classes (e.g. TimeSpan) that you could use in your code that would also need to have their "value" properties serialized.
    Code:
    [Browsable(false)]
    public string PaintColorSerialize
    {
         get { return NinjaTrader.Gui.Design.SerializableColor.ToString(paintColor); }
         set { paintColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
    }
    Attached is a NinjaScript indicator sample that uses two user definable color inputs to determine the color of a drawn rectangle.
    Attached Files
    Last edited by NinjaTrader_Jesse; 06-03-2015, 03:44 PM.
    Josh P.NinjaTrader Customer Service

    #2
    Applies to NinjaTrader 8

    User definable inputs do not need to be limited to numeric values. You can have brushes as an input as well. To do this you will need to make a public property for a Brush object instead of an int or double.

    In the "Properties" region of your code, there is only a slight change in the code snippet you would normally use to create user definable inputs.
    Code:
    [XmlIgnore()]
    [Display(Name = "BorderBrush", GroupName = "NinjaScriptParameters", Order = 0)]
    The second difference is in the next line of code:
    Code:
    public Brush BorderBrush
    { get; set; }
    This creates a brush input for use in the dialog window when we try to add the NinjaScript to a chart.

    Some additional extra code that is required for creating a color input is to serialize the brush. Serialization is necessary for NinjaTrader to use the brush input throughout the program. Please note that serialization is a general concept not exclusive to brush inputs. There may be other struct/classes (e.g. TimeSpan) that you could use in your code that would also need to have their "value" properties serialized.
    Code:
    [Browsable(false)]
    public string BorderBrushSerialize
    {
    	get { return Serialize.BrushToString(BorderBrush); }
       	set { BorderBrush = Serialize.StringToBrush(value); }
    }
    Attached is a NinjaScript indicator sample that uses two user definable brush inputs to determine the color of a drawn rectangle.
    Attached Files
    Last edited by NinjaTrader_MichaelM; 06-23-2015, 02:06 PM.
    Michael M.NinjaTrader Quality Assurance

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by rtwave, 04-12-2024, 09:30 AM
    2 responses
    20 views
    0 likes
    Last Post rtwave
    by rtwave
     
    Started by tsantospinto, 04-12-2024, 07:04 PM
    5 responses
    68 views
    0 likes
    Last Post tsantospinto  
    Started by cre8able, Today, 03:20 PM
    0 responses
    7 views
    0 likes
    Last Post cre8able  
    Started by Fran888, 02-16-2024, 10:48 AM
    3 responses
    49 views
    0 likes
    Last Post Sam2515
    by Sam2515
     
    Started by martin70, 03-24-2023, 04:58 AM
    15 responses
    115 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X