Serializing Brush Parameters in NinjaTrader      



Quite often, if you do not serialize your Brush parameters in your NinjaTrader strategy or indicator you will be fine but only until you try saving your presets. When a preset is saved all parameters are actually serialized into a string on the backend and if you have not handled the Brush parameter properly in your code then you will get a problem, you won't be able to save parameters and NinjaTrader might also crash. Below is how to properly handle this situation:


        [XmlIgnore]
        [NinjaScriptProperty]
        [Display(Order = 20, Name = "Dıamond Color", GroupName = "Parameters")]
        public System.Windows.Media.Brush DıamondColor { get; set; }


        [Browsable(false)]
        public string MyBrushSerialize
        {
            get { return Serialize.BrushToString(DıamondColor); }
            set { DıamondColor = Serialize.StringToBrush(value); }
        }