View Single Post
Old 06-23-2015, 02:00 PM   #2
NinjaTrader_MichaelM
NinjaTrader Customer Service
 
NinjaTrader_MichaelM's Avatar
 
Join Date: Apr 2015
Posts: 725
Thanks: 69
Thanked 205 times in 179 posts
Default

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
File Type: zip SampleBrushInput_NT8.zip (1.7 KB, 759 views)
Last edited by NinjaTrader_MichaelM; 06-23-2015 at 02:06 PM.
NinjaTrader_MichaelM is offline  
Reply With Quote
The following 8 users say thank you to NinjaTrader_MichaelM for this post: