NinjaScript > Educational Resources > Tips >

User Definable Color Inputs

Print this Topic Previous pageReturn to chapter overviewNext page

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.


[Description("Color for painted region")]



The second difference is in the next line of code:

public 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.


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.