Modify NinjaTrader 7 Dynamic Property View

,
NinjaTrader Logo
NinjaTrader 7 uses a GridControl to let the user modify strategy or indicator properties. Properties marked with certain tags will be shown automatically in the Grid.
Example:
[Description("Numbers of bars used for calculations")]
[GridCategory("Parameters")]
public int Period {
    get {return iPeriod;} 
    set {iPeriod = Math.Max(1, value);}
}
It is possible to hide parameters in the GridControl dynamically. For supporting  this feature the strategy has to implement the interface ICustomTypeDescriptor. The property which allows to modify the visibility of other properties in the GridControl has to get additionally the tag RefreshProperties(RefreshProperties.All). Finally the function ModifyProperties implements the visibility handling.
public class tF_TestAnn : Strategy, ICustomTypeDescriptor
{
        [Description("ANN trade mode.")]
        [GridCategory("Parameters")]
        [RefreshProperties(RefreshProperties.All)]
        public  ENAnnMode AnnMode { get; set; }
 
        private void ModifyProperties(PropertyDescriptorCollection col)
        {
            if( AnnMode != ENAnnMode.Backtest )
            {
                col.Remove(col.Find("NetType", true));
            }
            if( AnnMode != ENAnnMode.Live )
            {
                col.Remove(col.Find("BuyLevel", true));
            }
        }

        public AttributeCollection GetAttributes()
        {
            return TypeDescriptor.GetAttributes(GetType());
        }

        public string GetClassName()
        {
            return TypeDescriptor.GetClassName(GetType());
        }

        public string GetComponentName()
        {
            return TypeDescriptor.GetComponentName(GetType());
        }

        public TypeConverter GetConverter()
        {
            return TypeDescriptor.GetConverter(GetType());
        }

        public EventDescriptor GetDefaultEvent()
        {
            return TypeDescriptor.GetDefaultEvent(GetType());
        }

        public PropertyDescriptor GetDefaultProperty()
        {
            return TypeDescriptor.GetDefaultProperty(GetType());
        }

        public object GetEditor(Type editorBaseType)
        {
            return TypeDescriptor.GetEditor(GetType(), editorBaseType);
        }

        public EventDescriptorCollection GetEvents(Attribute[] attributes)
        {
            return TypeDescriptor.GetEvents(GetType(), attributes);
        }

        public EventDescriptorCollection GetEvents()
        {
            return TypeDescriptor.GetEvents(GetType());
        }

        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            PropertyDescriptorCollection orig = TypeDescriptor.GetProperties(GetType(), attributes);
            PropertyDescriptor[] arr = new PropertyDescriptor[orig.Count];
            orig.CopyTo(arr, 0);
            PropertyDescriptorCollection col = new PropertyDescriptorCollection(arr);

            ModifyProperties(col);
            return col;

        }

        public PropertyDescriptorCollection GetProperties()
        {
            return TypeDescriptor.GetProperties(GetType());
        }

        public object GetPropertyOwner(PropertyDescriptor pd)
        {
            return this;
        }
}
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *