Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to get the enum's inputs displayed on the Strategy Prope

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

    how to get the enum's inputs displayed on the Strategy Prope

    I can't check yet.

    New problem:

    Given what follows, how to get the enum's inputs displayed on the Strategy Properties Windows other than with the static keyword?





    ( in this short clip, only "Method 2" enum variable is displayed because it is both non static and not used in the EnumtoLabelConverter : TypeConverter class,
    whereas "Method 1" enum variable, which is used in the EnumtoLabelConverter : TypeConverter class), can't be displayed because it would need to be non-static but if it is the error below is thrown)

    If I remove the static keyword from this line,
    Code:
    public static MyEnum5 St1EnumVar
    ,
    then it throws this error:
    NinjaScript File Error Code Line Column
    MyEnum5.cs An object reference is required for the non-static field, method, or property 'NinjaTrader.NinjaScript.Strategies._MyEnum5.St1En umVar.get' CS0120 253 12
    But if i keep it, then the enum does not display on the Strategy Properties Windows from the chart.

    The script needed this editing to show the enums inputs on the Strategy Properties Windows from the chart :

    Code:
    #region Using declarations
    using NinjaTrader.Cbi;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui;
    using NinjaTrader.NinjaScript.DrawingTools;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Collections;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows;
    using System.Xml.Serialization;
    using System;
    #endregion
    
    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
        
        public class _MyEnum5 : Strategy
        {
            
            #region #3 CLASS VARIABLES - State.SetDefaults : ENUM LOOP BUTTON LABEL == BUTTON ENUM STRING
                
                public static string btn1Lbl, btn2Lbl;
    
                // Create a variable that stores the user's selection for a moving average
                //public static MyEnum5 st1EnumVar, nd2EnumVar;
    
            #endregion
            
            #region (OnStateChange)
            
                protected override void OnStateChange()
                {    
                    #region (State == State.SetDefaults)
                    
                        if (State == State.SetDefaults)
                        {
                            Description                                    = @"";
                            Name                                        = "_MyEnum5";
                            Calculate                                    = Calculate.OnBarClose;
                            EntriesPerDirection                            = 7;
                            EntryHandling                                = EntryHandling.AllEntries;
                            IsExitOnSessionCloseStrategy                = true;
                            ExitOnSessionCloseSeconds                    = 30;
                            IsFillLimitOnTouch                            = false;
                            
                            #region OnRender requires .Infinite
                            
                                MaximumBarsLookBack                        = MaximumBarsLookBack.Infinite;
                            
                            #endregion
                            
                            OrderFillResolution                            = OrderFillResolution.Standard;
                            Slippage                                    = 0;
                            StartBehavior                                = StartBehavior.ImmediatelySubmitSynchronizeAccount;
                            TimeInForce                                    = TimeInForce.Gtc;
                            TraceOrders                                    = false;
                            RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                            StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                            BarsRequiredToTrade                            = 20;
                            // Disable this property for performance gains in Strategy Analyzer optimizations
                            // See the Help Guide for additional information
                            IsInstantiatedOnEachOptimizationIteration    = true;
                    
                            #region BUTTONS PARAMETERS - BUTTONS METHOD ENUM SELECTORS
                    
                                St1EnumVar                    = MyEnum5.X;
                                Nd2EnumVar                    = MyEnum5.B;
                        
                            #endregion
                        
                            #region BUTTONS PARAMETERS
                                Button1Label                = Btn1Lbl;
                                
                                Button2Label                = Btn2Lbl;
                            
                            #endregion
    
                        }
                        
                    #endregion
                    
                    #region (State == State.Configure)
                    
                        else if (State == State.Configure)
                        {
                        }
                        
                    #endregion
                    
                    #region (State == State.Historical)
                    
                        else if (State == State.Historical)
                        {
                        }
                        
                    #endregion
                        
                    #region (State == State.Terminated)
    
                        else if (State == State.Terminated)
                        {
                        }
                        
                    #endregion
                }
            
            #endregion
            
            #region REMOVE PARAMETERS LABELS FROM CHART
    
                public override string DisplayName
                {
                    get {return this.Name;}
                }
    
            #endregion
            
            #region OnBarUpdate()
            
                protected override void OnBarUpdate()
                {
                }
    
            #endregion
            
    
            #region #2 PROPERTIES
            
                #region BUTTONS 1 TO 6
    
                    #region Button 1 Parameters
                        
                                            
                        [TypeConverter(typeof(EnumtoLabelConverter))] // Converts the enum to string values
                        [PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")]
                        [Display(Name="Methods 1", Description="", Order=1, GroupName="Methods 1")]
                        //[RefreshProperties(RefreshProperties.All)]
                        public static MyEnum5 St1EnumVar
                        { get; set; }
                    
                        [NinjaScriptProperty]
                        [Display(Name="Label Button 1", Order=2, GroupName="Parameters")]
                        public string Button1Label
                        { get; set; }
                    
                        [NinjaScriptProperty]
                        [Display(Name="Label Btn1Lbl ", Order=3, GroupName="Parameters")]
                        public static string Btn1Lbl
                        { get; set; }
                        
                    #endregion
                    
                
                    #region Button 2 Parameters
                        
                        [TypeConverter(typeof(EnumtoLabelConverter))] // Converts the enum to string values
                        [PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")]
                        [Display(Name="Methods 2", Description="", Order=4, GroupName="Methods 2")]
                        //[RefreshProperties(RefreshProperties.All)]
                        public MyEnum5 Nd2EnumVar
                        { get; set; }
                    
                        [NinjaScriptProperty]
                        [Display(Name="Label Button 2", Order=5, GroupName="Parameters")]
                        public string Button2Label
                        { get; set; }
                    
                        [NinjaScriptProperty]
                        [Display(Name="Label Btn2Lbl", Order=6, GroupName="Parameters")]
                        public string Btn2Lbl
                        { get; set; }
                        
                    #endregion
            
                #endregion
                
            #endregion
        }
    
        #region ENUMS
    
            public enum MyEnum5
            { A, B, C, X, Y, Z }
    
        #endregion
        
        #region
            
            // Since this is only being applied to a specific property rather than the whole class,
            // we don't need to inherit from IndicatorBaseConverter and we can just use a generic TypeConverter
            public class EnumtoLabelConverter : TypeConverter
            {
                // Set the values to appear in the combo box
                public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
                {
                    List<string> values = new List<string>()
                    { "A","B","C","X","Y","Z" };
    
                    return new StandardValuesCollection(values);
                }
    
                // map the MyEnum type to "Friendly" string
                public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
                {
                    MyEnum5 stringVal = (MyEnum5) Enum.Parse(typeof(MyEnum5), value.ToString());
                    
                    if (_MyEnum5.St1EnumVar == stringVal)
                    {
                        _MyEnum5.btn1Lbl = value.ToString();
                        return _MyEnum5.btn1Lbl; // Return the label if the condition is met
                    }
                    
                    return string.Empty; // Return an empty string if the condition is not met
                }
    
                // required interface members needed to compile
                public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
                { return true; }                                                                                                                                                        
    
                public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
                { return true; }
    
                public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
                { return true; }
    
                public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
                { return true; }
            }
            
        #endregion
    }

    Reduced pseudocode:

    Code:
    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
        
        public class _MyEnum5 : Strategy
        {
            protected override void OnStateChange()
            {
                
                if (State == State.SetDefaults)
                {
            
                    St1EnumVar        = MyEnum5.X;
                    Nd2EnumVar        = MyEnum5.B;
    
                }
            }
            
            [TypeConverter(typeof(EnumtoLabelConverter))] // Converts the enum to string values
            [PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")]
            [Display(Name="Methods 1", Description="", Order=1, GroupName="Methods 1")]
            //[RefreshProperties(RefreshProperties.All)]
            public MyEnum5 St1EnumVar
            { get; set; }
            
            [TypeConverter(typeof(EnumtoLabelConverter))] // Converts the enum to string values
            [PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")]
            [Display(Name="Methods 2", Description="", Order=4, GroupName="Methods 2")]
            //[RefreshProperties(RefreshProperties.All)]
            public MyEnum5 Nd2EnumVar
            { get; set; }
        }
    
        public enum MyEnum5
        { A, B, C, X, Y, Z }
        
        public class EnumtoLabelConverter : TypeConverter
        {
            // Set the values to appear in the combo box
            public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                List<string> values = new List<string>()
                { "A","B","C","X","Y","Z" };
        
                return new StandardValuesCollection(values);
            }
        
            // map the MyEnum type to "Friendly" string
            public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
            {
                MyEnum5 stringVal = (MyEnum5) Enum.Parse(typeof(MyEnum5), value.ToString());
                
                if (_MyEnum5.St1EnumVar == stringVal)
                {
                    _MyEnum5.btn1Lbl = value.ToString();
                    return _MyEnum5.btn1Lbl; // Return the label if the condition is met
                }
                
                return string.Empty; // Return an empty string if the condition is not met
            }
        
            // required interface members needed to compile
            public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
            { return true; }                                                                                                                                                        
        
            public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
            { return true; }
        
            public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
            { return true; }
        
            public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
            { return true; }
        }
    }
     
    
    ​
    Last edited by PaulMohn; 08-27-2024, 08:20 AM.

    #2
    Hello PaulMohn,

    I've moved this post to a new thread as this is a new subject that is not related to the previous thread.

    It sounds like you want to show "Friendly" enum values.

    The property should not be static.

    Have a look at the SampleIndicatorTypeConverter which provides a working example linked below on lines 227 through 231, 546 through 611.

    A switch (similar to if statements) is used to choose the displayed text in the combo-box on lines 587 to 595. This is similar to the test script I have provided you.

    I recommend using this as your starting point so you have a working script and then add your code to it.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_ChelseaB,

      I'm inquiring about doing it with an if statement, not a switch, because I need to check for boolean values not constants.

      How do you suggest doing it with an if statement not using the static keyword?

      Code:
                      
                      if (_MyEnum5.St1EnumVar == stringVal)
                      {
                          _MyEnum5.btn1Lbl = value.ToString();
                          return _MyEnum5.btn1Lbl; // Return the label if the condition is met
                      }
                      
                      return string.Empty; // Return an empty string if the condition is not met​

      Comment


        #4
        Hello PaulMohn,

        A switch would work with any object type, including bools.

        That said, the same code using an if statement instead of a switch would appear as:

        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
        MyEnum stringVal = (MyEnum) Enum.Parse(typeof(MyEnum), value.ToString());

        if (stringVal == MyEnum.MyCustom1)
        {
        return "My custom one";
        }
        else if (stringVal == MyEnum.MyCustom2)
        {
        return "My custom two";
        }
        else if (stringVal == MyEnum.MyCustom3)
        {
        return "My custom three";
        }

        return string.Empty;
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          NinjaTrader_ChelseaB,

          What about the not using the static keyword part of the enquiry, since the if statement is supposed to work as well as the switch?

          Comment


            #6
            I also tested with the Use case #3
            (lines 506-43 of the SampleStrategyTypeConverter script
            https://pastecode.io/s/jsbeh2ws ) which also throws the non-static error:

            Code:
            
                    // Since this is only being applied to a specific property rather than the whole class,
                    // we don't need to inherit from IndicatorBaseConverter and we can just use a generic TypeConverter
                    public class EnumtoLabelConverter : TypeConverter
                    {
                        // Set the values to appear in the combo box
                        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
                        {
                            List<string> values = new List<string>()
                            { "A","B","C","X","Y","Z" };
            
                            return new StandardValuesCollection(values);
                        }
                        
            
                        // map the value from "Friendly" string to bool type
                        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
                        {
                            MyEnum5 stringVal = (MyEnum5) Enum.Parse(typeof(MyEnum5), value.ToString());
                            
                            return ( _MyEnum5.St1EnumVar == stringVal ) ? true : false;
                        }
            
                        // map the bool type to "Friendly" string
                        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
                        {
                            return (bool) value ? _MyEnum5.btn1Lbl : string.Empty;
                        }
            
                        // required interface members needed to compile
                        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
                        { return true; }                                                                                                                                                        
            
                        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
                        { return true; }
            
                        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
                        { return true; }
            
                        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
                        { return true; }
                    }​
                    ​


            NinjaScript File Error Code Line Column
            MyEnum5.cs An object reference is required for the non-static field, method, or property 'NinjaTrader.NinjaScript.Strategies._MyEnum5.St1En umVar.get' CS0120 254 23


            Code:
            #region Using declarations
            using NinjaTrader.Cbi;
            using NinjaTrader.Core.FloatingPoint;
            using NinjaTrader.Data;
            using NinjaTrader.Gui.Chart;
            using NinjaTrader.Gui.SuperDom;
            using NinjaTrader.Gui;
            using NinjaTrader.NinjaScript.DrawingTools;
            using NinjaTrader.NinjaScript.Indicators;
            using NinjaTrader.NinjaScript;
            using System.Collections.Generic;
            using System.Collections.ObjectModel;
            using System.Collections;
            using System.ComponentModel.DataAnnotations;
            using System.ComponentModel;
            using System.Globalization;
            using System.IO;
            using System.Linq;
            using System.Reflection;
            using System.Text;
            using System.Threading.Tasks;
            using System.Windows.Input;
            using System.Windows.Media;
            using System.Windows;
            using System.Xml.Serialization;
            using System;
            #endregion
            
            //This namespace holds Strategies in this folder and is required. Do not change it.
            namespace NinjaTrader.NinjaScript.Strategies
            {
                
                public class _MyEnum5 : Strategy
                {
                    
                    #region #3 CLASS VARIABLES - State.SetDefaults : ENUM LOOP BUTTON LABEL == BUTTON ENUM STRING
                        
                        public static string btn1Lbl, btn2Lbl;
            
                        // Create a variable that stores the user's selection for a moving average
                        //public static MyEnum5 st1EnumVar, nd2EnumVar;
            
                    #endregion
                    
                    #region (OnStateChange)
                    
                        protected override void OnStateChange()
                        {    
                            #region (State == State.SetDefaults)
                            
                                if (State == State.SetDefaults)
                                {
                                    Description                                    = @"";
                                    Name                                        = "_MyEnum5";
                                    Calculate                                    = Calculate.OnBarClose;
                                    EntriesPerDirection                            = 7;
                                    EntryHandling                                = EntryHandling.AllEntries;
                                    IsExitOnSessionCloseStrategy                = true;
                                    ExitOnSessionCloseSeconds                    = 30;
                                    IsFillLimitOnTouch                            = false;
                                    
                                    #region OnRender requires .Infinite
                                    
                                        MaximumBarsLookBack                        = MaximumBarsLookBack.Infinite;
                                    
                                    #endregion
                                    
                                    OrderFillResolution                            = OrderFillResolution.Standard;
                                    Slippage                                    = 0;
                                    StartBehavior                                = StartBehavior.ImmediatelySubmitSynchronizeAccount;
                                    TimeInForce                                    = TimeInForce.Gtc;
                                    TraceOrders                                    = false;
                                    RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                                    StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                                    BarsRequiredToTrade                            = 20;
                                    // Disable this property for performance gains in Strategy Analyzer optimizations
                                    // See the Help Guide for additional information
                                    IsInstantiatedOnEachOptimizationIteration    = true;
                            
                                    #region BUTTONS PARAMETERS - BUTTONS METHOD ENUM SELECTORS
                            
                                        St1EnumVar                    = MyEnum5.X;
                                        Nd2EnumVar                    = MyEnum5.B;
                                
                                    #endregion
                                
                                    #region BUTTONS PARAMETERS
                                        Button1Label                = Btn1Lbl;
                                        
                                        Button2Label                = Btn2Lbl;
                                    
                                    #endregion
            
                                }
                                
                            #endregion
                            
                            #region (State == State.Configure)
                            
                                else if (State == State.Configure)
                                {
                                }
                                
                            #endregion
                            
                            #region (State == State.Historical)
                            
                                else if (State == State.Historical)
                                {
                                }
                                
                            #endregion
                                
                            #region (State == State.Terminated)
            
                                else if (State == State.Terminated)
                                {
                                }
                                
                            #endregion
                        }
                    
                    #endregion
                    
                    #region REMOVE PARAMETERS LABELS FROM CHART
            
                        public override string DisplayName
                        {
                            get {return this.Name;}
                        }
            
                    #endregion
                    
                    #region OnBarUpdate()
                    
                        protected override void OnBarUpdate()
                        {
                        }
            
                    #endregion
                    
            
                    #region #2 PROPERTIES
                    
                        #region BUTTONS 1 TO 6
            
                            #region Button 1 Parameters
                                
                                                    
                                [TypeConverter(typeof(EnumtoLabelConverter))] // Converts the enum to string values
                                [PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")]
                                [Display(Name="Methods 1", Description="", Order=1, GroupName="Methods 1")]
                                //[RefreshProperties(RefreshProperties.All)]
                                public MyEnum5 St1EnumVar
                                { get; set; }
                            
                                [NinjaScriptProperty]
                                [Display(Name="Label Button 1", Order=2, GroupName="Parameters")]
                                public string Button1Label
                                { get; set; }
                            
                                [NinjaScriptProperty]
                                [Display(Name="Label Btn1Lbl ", Order=3, GroupName="Parameters")]
                                public string Btn1Lbl
                                { get; set; }
                                
                            #endregion
                            
                        
                            #region Button 2 Parameters
                                
                                [TypeConverter(typeof(EnumtoLabelConverter))] // Converts the enum to string values
                                [PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")]
                                [Display(Name="Methods 2", Description="", Order=4, GroupName="Methods 2")]
                                //[RefreshProperties(RefreshProperties.All)]
                                public MyEnum5 Nd2EnumVar
                                { get; set; }
                            
                                [NinjaScriptProperty]
                                [Display(Name="Label Button 2", Order=5, GroupName="Parameters")]
                                public string Button2Label
                                { get; set; }
                            
                                [NinjaScriptProperty]
                                [Display(Name="Label Btn2Lbl", Order=6, GroupName="Parameters")]
                                public string Btn2Lbl
                                { get; set; }
                                
                            #endregion
                    
                        #endregion
                        
                    #endregion
                }
            
                #region ENUMS
            
                    public enum MyEnum5
                    { A, B, C, X, Y, Z }
            
                #endregion
                
                #region
                    
                    // Since this is only being applied to a specific property rather than the whole class,
                    // we don't need to inherit from IndicatorBaseConverter and we can just use a generic TypeConverter
                    public class EnumtoLabelConverter : TypeConverter
                    {
                        // Set the values to appear in the combo box
                        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
                        {
                            List<string> values = new List<string>()
                            { "A","B","C","X","Y","Z" };
            
                            return new StandardValuesCollection(values);
                        }
                        
            
                        // map the value from "Friendly" string to bool type
                        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
                        {
                            MyEnum5 stringVal = (MyEnum5) Enum.Parse(typeof(MyEnum5), value.ToString());
                            
                            return ( _MyEnum5.St1EnumVar == stringVal ) ? true : false;
                        }
            
                        // map the bool type to "Friendly" string
                        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
                        {
                            return (bool) value ? _MyEnum5.btn1Lbl : string.Empty;
                        }
            
                        // required interface members needed to compile
                        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
                        { return true; }                                                                                                                                                        
            
                        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
                        { return true; }
            
                        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
                        { return true; }
            
                        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
                        { return true; }
                    }
                    
                #endregion
            }
            Last edited by PaulMohn; 08-27-2024, 12:28 PM.

            Comment


              #7
              Hello PaulMohn,

              The reference sample does not use the static keyword.

              Are you looking at a modified version of the reference sample.

              If so, redownload the original version from the help guide. You will see the static keyword is not used on lines 227 through 231 and the sample does not have any errors.


              Further, static classes and variables are not officially supported by NinjaTrader.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Are you looking at a modified version of the reference sample.
                I'm refering to this script:

                Code:
                using NinjaTrader.Cbi;
                using NinjaTrader.Core.FloatingPoint;
                using NinjaTrader.Data;
                using NinjaTrader.Gui.Chart;
                using NinjaTrader.Gui.SuperDom;
                using NinjaTrader.Gui;
                using NinjaTrader.NinjaScript.DrawingTools;
                using NinjaTrader.NinjaScript.Indicators;
                using NinjaTrader.NinjaScript;
                using System.Collections.Generic;
                using System.Collections.ObjectModel;
                using System.Collections;
                using System.ComponentModel.DataAnnotations;
                using System.ComponentModel;
                using System.Globalization;
                using System.IO;
                using System.Linq;
                using System.Reflection;
                using System.Text;
                using System.Threading.Tasks;
                using System.Windows.Input;
                using System.Windows.Media;
                using System.Windows;
                using System.Xml.Serialization;
                using System;
                #endregion
                
                //This namespace holds Strategies in this folder and is required. Do not change it.
                namespace NinjaTrader.NinjaScript.Strategies
                {
                    
                    public class _MyEnum5 : Strategy
                    {
                        
                        #region #3 CLASS VARIABLES - State.SetDefaults : ENUM LOOP BUTTON LABEL == BUTTON ENUM STRING
                            
                            public static string btn1Lbl, btn2Lbl;
                
                            // Create a variable that stores the user's selection for a moving average
                            //public static MyEnum5 st1EnumVar, nd2EnumVar;
                
                        #endregion
                        
                        #region (OnStateChange)
                        
                            protected override void OnStateChange()
                            {    
                                #region (State == State.SetDefaults)
                                
                                    if (State == State.SetDefaults)
                                    {
                                        Description                                    = @"";
                                        Name                                        = "_MyEnum5";
                                        Calculate                                    = Calculate.OnBarClose;
                                        EntriesPerDirection                            = 7;
                                        EntryHandling                                = EntryHandling.AllEntries;
                                        IsExitOnSessionCloseStrategy                = true;
                                        ExitOnSessionCloseSeconds                    = 30;
                                        IsFillLimitOnTouch                            = false;
                                        
                                        #region OnRender requires .Infinite
                                        
                                            MaximumBarsLookBack                        = MaximumBarsLookBack.Infinite;
                                        
                                        #endregion
                                        
                                        OrderFillResolution                            = OrderFillResolution.Standard;
                                        Slippage                                    = 0;
                                        StartBehavior                                = StartBehavior.ImmediatelySubmitSynchronizeAccount;
                                        TimeInForce                                    = TimeInForce.Gtc;
                                        TraceOrders                                    = false;
                                        RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                                        StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                                        BarsRequiredToTrade                            = 20;
                                        // Disable this property for performance gains in Strategy Analyzer optimizations
                                        // See the Help Guide for additional information
                                        IsInstantiatedOnEachOptimizationIteration    = true;
                                
                                        #region BUTTONS PARAMETERS - BUTTONS METHOD ENUM SELECTORS
                                
                                            St1EnumVar                    = MyEnum5.X;
                                            Nd2EnumVar                    = MyEnum5.B;
                                    
                                        #endregion
                                    
                                        #region BUTTONS PARAMETERS
                                            Button1Label                = Btn1Lbl;
                                            
                                            Button2Label                = Btn2Lbl;
                                        
                                        #endregion
                
                                    }
                                    
                                #endregion
                                
                                #region (State == State.Configure)
                                
                                    else if (State == State.Configure)
                                    {
                                    }
                                    
                                #endregion
                                
                                #region (State == State.Historical)
                                
                                    else if (State == State.Historical)
                                    {
                                    }
                                    
                                #endregion
                                    
                                #region (State == State.Terminated)
                
                                    else if (State == State.Terminated)
                                    {
                                    }
                                    
                                #endregion
                            }
                        
                        #endregion
                        
                        #region REMOVE PARAMETERS LABELS FROM CHART
                
                            public override string DisplayName
                            {
                                get {return this.Name;}
                            }
                
                        #endregion
                        
                        #region OnBarUpdate()
                        
                            protected override void OnBarUpdate()
                            {
                            }
                
                        #endregion
                        
                
                        #region #2 PROPERTIES
                        
                            #region BUTTONS 1 TO 6
                
                                #region Button 1 Parameters
                                    
                                                        
                                    [TypeConverter(typeof(EnumtoLabelConverter))] // Converts the enum to string values
                                    [PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")]
                                    [Display(Name="Methods 1", Description="", Order=1, GroupName="Methods 1")]
                                    //[RefreshProperties(RefreshProperties.All)]
                                    public MyEnum5 St1EnumVar
                                    { get; set; }
                                
                                    [NinjaScriptProperty]
                                    [Display(Name="Label Button 1", Order=2, GroupName="Parameters")]
                                    public string Button1Label
                                    { get; set; }
                                
                                    [NinjaScriptProperty]
                                    [Display(Name="Label Btn1Lbl ", Order=3, GroupName="Parameters")]
                                    public string Btn1Lbl
                                    { get; set; }
                                    
                                #endregion
                                
                            
                                #region Button 2 Parameters
                                    
                                    [TypeConverter(typeof(EnumtoLabelConverter))] // Converts the enum to string values
                                    [PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")]
                                    [Display(Name="Methods 2", Description="", Order=4, GroupName="Methods 2")]
                                    //[RefreshProperties(RefreshProperties.All)]
                                    public MyEnum5 Nd2EnumVar
                                    { get; set; }
                                
                                    [NinjaScriptProperty]
                                    [Display(Name="Label Button 2", Order=5, GroupName="Parameters")]
                                    public string Button2Label
                                    { get; set; }
                                
                                    [NinjaScriptProperty]
                                    [Display(Name="Label Btn2Lbl", Order=6, GroupName="Parameters")]
                                    public string Btn2Lbl
                                    { get; set; }
                                    
                                #endregion
                        
                            #endregion
                            
                        #endregion
                    }
                
                    #region ENUMS
                
                        public enum MyEnum5
                        { A, B, C, X, Y, Z }
                
                    #endregion
                    
                    #region
                        
                        // Since this is only being applied to a specific property rather than the whole class,
                        // we don't need to inherit from IndicatorBaseConverter and we can just use a generic TypeConverter
                        public class EnumtoLabelConverter : TypeConverter
                        {
                            // Set the values to appear in the combo box
                            public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
                            {
                                List<string> values = new List<string>()
                                { "A","B","C","X","Y","Z" };
                
                                return new StandardValuesCollection(values);
                            }
                            
                
                            // map the value from "Friendly" string to bool type
                            public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
                            {
                                MyEnum5 stringVal = (MyEnum5) Enum.Parse(typeof(MyEnum5), value.ToString());
                                
                                return ( _MyEnum5.St1EnumVar == stringVal ) ? true : false;
                            }
                
                            // map the bool type to "Friendly" string
                            public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
                            {
                                return (bool) value ? _MyEnum5.btn1Lbl : string.Empty;
                            }
                
                            // required interface members needed to compile
                            public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
                            { return true; }                                                                                                                                                        
                
                            public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
                            { return true; }
                
                            public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
                            { return true; }
                
                            public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
                            { return true; }
                        }
                        
                    #endregion
                }
                Look at this script. then answer the question.

                I make use of this variable:

                Code:
                public MyEnum5 St1EnumVar
                within these methods:


                Code:
                // map the value from "Friendly" string to bool type
                public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
                {
                MyEnum5 stringVal = (MyEnum5) Enum.Parse(typeof(MyEnum5), value.ToString());
                
                return ( _MyEnum5.St1EnumVar == stringVal ) ? true : false;
                }
                
                // map the bool type to "Friendly" string
                public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
                {
                return (bool) value ? _MyEnum5.btn1Lbl : string.Empty;
                }​
                The SampleStrategyTypeConverter script does not make references to a conditionnal statement involving a variable from the strategy class so it is improper for use as is as a meaningful reference to the case in point.

                Last edited by PaulMohn; 08-27-2024, 12:45 PM.

                Comment


                  #9
                  Hello PaulMohn,

                  As mentioned in post # 2 of this thread, I recommend using this as your starting point so you have a working script and then add your code to it.

                  Alternatively, if you would like someone to debug your code as a convenience to you, you can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.

                  The error "An object reference is required for the non-static field, method, or property" typically means that a new instance of an object is not being assigned.

                  You will need to identify the specific line of code causing the error (that when commented out dissolves the error)​.
                  I recommend adding prints above each line to see which print is the last to appear before the error occurs.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Are you saying the TypeConverter Class needs an instance of the Strategy class?

                    The specific line causing the error is this one:
                    Code:
                     return ( _MyEnum5.St1EnumVar == stringVal ) ? true : false;​

                    Comment


                      #11
                      Hello PaulMohn,

                      Try returning a string instead as this is what will be used.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Ok.

                        This compiles, but not output in the enums yet:

                        Code:
                        #region Using declarations
                        using NinjaTrader.Cbi;
                        using NinjaTrader.Core.FloatingPoint;
                        using NinjaTrader.Data;
                        using NinjaTrader.Gui.Chart;
                        using NinjaTrader.Gui.SuperDom;
                        using NinjaTrader.Gui;
                        using NinjaTrader.NinjaScript.DrawingTools;
                        using NinjaTrader.NinjaScript.Indicators;
                        using NinjaTrader.NinjaScript;
                        using System.Collections.Generic;
                        using System.Collections.ObjectModel;
                        using System.Collections;
                        using System.ComponentModel.DataAnnotations;
                        using System.ComponentModel;
                        using System.Globalization;
                        using System.IO;
                        using System.Linq;
                        using System.Reflection;
                        using System.Text;
                        using System.Threading.Tasks;
                        using System.Windows.Input;
                        using System.Windows.Media;
                        using System.Windows;
                        using System.Xml.Serialization;
                        using System;
                        #endregion
                        
                        //This namespace holds Strategies in this folder and is required. Do not change it.
                        namespace NinjaTrader.NinjaScript.Strategies
                        {
                            
                            public class _MyEnum5 : Strategy
                            {
                                
                                #region #3 CLASS VARIABLES - State.SetDefaults : ENUM LOOP BUTTON LABEL == BUTTON ENUM STRING
                                    
                                    public static string btn1Lbl, btn2Lbl;
                        
                                    // Create a variable that stores the user's selection for a moving average
                                    //public static MyEnum5 st1EnumVar, nd2EnumVar;
                        
                                #endregion
                                
                                #region (OnStateChange)
                                
                                    protected override void OnStateChange()
                                    {    
                                        #region (State == State.SetDefaults)
                                        
                                            if (State == State.SetDefaults)
                                            {
                                                Description                                    = @"";
                                                Name                                        = "_MyEnum5";
                                                Calculate                                    = Calculate.OnBarClose;
                                                EntriesPerDirection                            = 7;
                                                EntryHandling                                = EntryHandling.AllEntries;
                                                IsExitOnSessionCloseStrategy                = true;
                                                ExitOnSessionCloseSeconds                    = 30;
                                                IsFillLimitOnTouch                            = false;
                                                
                                                #region OnRender requires .Infinite
                                                
                                                    MaximumBarsLookBack                        = MaximumBarsLookBack.Infinite;
                                                
                                                #endregion
                                                
                                                OrderFillResolution                            = OrderFillResolution.Standard;
                                                Slippage                                    = 0;
                                                StartBehavior                                = StartBehavior.ImmediatelySubmitSynchronizeAccount;
                                                TimeInForce                                    = TimeInForce.Gtc;
                                                TraceOrders                                    = false;
                                                RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                                                StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                                                BarsRequiredToTrade                            = 20;
                                                // Disable this property for performance gains in Strategy Analyzer optimizations
                                                // See the Help Guide for additional information
                                                IsInstantiatedOnEachOptimizationIteration    = true;
                                        
                                                #region BUTTONS PARAMETERS - BUTTONS METHOD ENUM SELECTORS
                                        
                                                    St1EnumVar                    = MyEnum5.X;
                                                    Nd2EnumVar                    = MyEnum5.B;
                                            
                                                #endregion
                                            
                                                #region BUTTONS PARAMETERS
                                                    Button1Label                = Btn1Lbl;
                                                    
                                                    Button2Label                = Btn2Lbl;
                                                
                                                #endregion
                        
                                            }
                                            
                                        #endregion
                                        
                                        #region (State == State.Configure)
                                        
                                            else if (State == State.Configure)
                                            {
                                            }
                                            
                                        #endregion
                                        
                                        #region (State == State.Historical)
                                        
                                            else if (State == State.Historical)
                                            {
                                            }
                                            
                                        #endregion
                                            
                                        #region (State == State.Terminated)
                        
                                            else if (State == State.Terminated)
                                            {
                                            }
                                            
                                        #endregion
                                    }
                                
                                #endregion
                                
                                #region REMOVE PARAMETERS LABELS FROM CHART
                        
                                    public override string DisplayName
                                    {
                                        get {return this.Name;}
                                    }
                        
                                #endregion
                                
                                #region OnBarUpdate()
                                
                                    protected override void OnBarUpdate()
                                    {
                                    }
                        
                                #endregion
                                
                        
                                #region #2 PROPERTIES
                                
                                    #region BUTTONS 1 TO 6
                        
                                        #region Button 1 Parameters
                                            
                                                                
                                            [TypeConverter(typeof(EnumtoLabelConverter))] // Converts the enum to string values
                                            [PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")]
                                            [Display(Name="Methods 1", Description="", Order=1, GroupName="Methods 1")]
                                            //[RefreshProperties(RefreshProperties.All)]
                                            public MyEnum5 St1EnumVar
                                            { get; set; }
                                        
                                            [NinjaScriptProperty]
                                            [Display(Name="Label Button 1", Order=2, GroupName="Parameters")]
                                            public string Button1Label
                                            { get; set; }
                                        
                                            [NinjaScriptProperty]
                                            [Display(Name="Label Btn1Lbl ", Order=3, GroupName="Parameters")]
                                            public string Btn1Lbl
                                            { get; set; }
                                            
                                        #endregion
                                        
                                    
                                        #region Button 2 Parameters
                                            
                                            [TypeConverter(typeof(EnumtoLabelConverter))] // Converts the enum to string values
                                            [PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")]
                                            [Display(Name="Methods 2", Description="", Order=4, GroupName="Methods 2")]
                                            //[RefreshProperties(RefreshProperties.All)]
                                            public MyEnum5 Nd2EnumVar
                                            { get; set; }
                                        
                                            [NinjaScriptProperty]
                                            [Display(Name="Label Button 2", Order=5, GroupName="Parameters")]
                                            public string Button2Label
                                            { get; set; }
                                        
                                            [NinjaScriptProperty]
                                            [Display(Name="Label Btn2Lbl", Order=6, GroupName="Parameters")]
                                            public string Btn2Lbl
                                            { get; set; }
                                            
                                        #endregion
                                
                                    #endregion
                                    
                                #endregion
                            }
                        
                            #region ENUMS
                        
                                public enum MyEnum5
                                { A, B, C, X, Y, Z }
                        
                            #endregion
                            
                            #region
                                
                            public class EnumtoLabelConverter : TypeConverter
                            {
                                private readonly _MyEnum5 strategyInstance;
                        
                                // Constructor that takes an instance of _MyEnum5
                                public EnumtoLabelConverter(_MyEnum5 instance)
                                {
                                    strategyInstance = instance;
                                }
                        
                                // Set the values to appear in the combo box
                                public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
                                {
                                    List<string> values = new List<string>()
                                    { "A", "B", "C", "X", "Y", "Z" };
                        
                                    return new StandardValuesCollection(values);
                                }
                        
                                // map the value from "Friendly" string to bool type
                                public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
                                {
                                    MyEnum5 stringVal = (MyEnum5)Enum.Parse(typeof(MyEnum5), value.ToString());
                                    return (strategyInstance.St1EnumVar == stringVal) ? true : false;
                                }
                        
                                // map the bool type to "Friendly" string
                                public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
                                {
                                    return (bool)value ? strategyInstance.Btn1Lbl : string.Empty;
                                }
                        
                                // required interface members needed to compile
                                public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
                                {
                                    return true;
                                }
                        
                                public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
                                {
                                    return true;
                                }
                        
                                public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
                                {
                                    return true;
                                }
                        
                                public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
                                {
                                    return true;
                                }
                            }
                                
                            #endregion
                        }​

                        Comment


                          #13
                          Hello PaulMohn,

                          As a tip, to export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
                          1. Click Tools -> Export -> NinjaScript Add-on...
                          2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
                          3. Click the 'Export' button
                          4. Enter the script name in the value for 'File name:'
                          5. Choose a save location -> click Save
                          6. Click OK to clear the export location message
                          By default your exported file will be in the following location:
                          • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
                          Below is a link to the help guide on Exporting NinjaScripts.



                          That said, are you looking for output in the output window?

                          What print are you looking for output for?​
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Prints for the SampleStrategyTypeConverter script reduced to Use Case #4: Display "friendly" enum values:




                            Output:
                            tringVal2: MyCuston4
                            stringValE: MyCustom2
                            val: My custom one
                            val: My custom two
                            val: My custom three
                            stringVal2: MyCustom2
                            stringValE: MyCustom2
                            val: My custom one
                            val: My custom two
                            val: My custom three​
                            Script:
                            Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.


                            Code:
                            // https://forum.ninjatrader.com/forum/ninjatrader-8/strategy-development/1315837-how-to-get-the-enum-s-inputs-displayed-on-the-strategy-prope?p=1315983#post1315983
                            
                            // Copyright (C) 2018, NinjaTrader LLC <www.ninjatrader.com>.
                            
                            // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
                            
                            //
                            
                            #region Using declarations
                            
                            using NinjaTrader.Cbi;
                            
                            using NinjaTrader.Core.FloatingPoint;
                            
                            using NinjaTrader.Data;
                            
                            using NinjaTrader.Gui.Chart;
                            
                            using NinjaTrader.Gui.SuperDom;
                            
                            using NinjaTrader.Gui;
                            
                            using NinjaTrader.NinjaScript.DrawingTools;
                            
                            using NinjaTrader.NinjaScript.Indicators;
                            
                            using NinjaTrader.NinjaScript;
                            
                            using System.Collections.Generic;
                            
                            using System.Collections.ObjectModel;
                            
                            using System.Collections;
                            
                            using System.ComponentModel.DataAnnotations;
                            
                            using System.ComponentModel;
                            
                            using System.Globalization;
                            
                            using System.IO;
                            
                            using System.Linq;
                            
                            using System.Reflection;
                            
                            using System.Text;
                            
                            using System.Threading.Tasks;
                            
                            using System.Windows.Input;
                            
                            using System.Windows.Media;
                            
                            using System.Windows;
                            
                            using System.Xml.Serialization;
                            
                            using System;
                            
                            #endregion
                            
                             
                            
                            //This namespace holds strategies in this folder and is required. Do not change it.
                            
                            namespace NinjaTrader.NinjaScript.Strategies
                            
                            {
                            
                                // Notes:
                            
                                // Helper classes and type converters are defined below the indicator, separated by use case
                            
                                // Property definitions are documented as necessary in the Properties region
                            
                                // Debugging issues will likely require compiling NS in debug mode and attaching VS to ninjatrader.exe
                            
                                // Setting breakpoints to examine values and seeing debug output that NT creates is helpful
                            
                              
                            
                                public class _SampleStrategyTypeConverter1 : Strategy
                            
                                {
                            
                                  
                            
                                    protected override void OnStateChange()
                            
                                    {
                            
                                        if (State == State.SetDefaults)
                            
                                        {
                            
                                            Description                                 = @"Demonstrating using type converters to customize the Indicator property grid";
                            
                                            Name                                        = "_SampleStrategyTypeConverter1";
                            
                                            Calculate                                   = Calculate.OnBarClose;
                            
                                            EntriesPerDirection                         = 1;
                            
                                            EntryHandling                               = EntryHandling.AllEntries;
                            
                                            IsExitOnSessionCloseStrategy                = true;
                            
                                            ExitOnSessionCloseSeconds                   = 30;
                            
                                            IsFillLimitOnTouch                          = false;
                            
                                            MaximumBarsLookBack                         = MaximumBarsLookBack.TwoHundredFiftySix;
                            
                                            OrderFillResolution                         = OrderFillResolution.Standard;
                            
                                            Slippage                                    = 0;
                            
                                            StartBehavior                               = StartBehavior.WaitUntilFlat;
                            
                                            TimeInForce                                 = TimeInForce.Gtc;
                            
                                            TraceOrders                                 = false;
                            
                                            RealtimeErrorHandling                       = RealtimeErrorHandling.StopCancelClose;
                            
                                            StopTargetHandling                          = StopTargetHandling.PerEntryExecution;
                            
                                            BarsRequiredToTrade                         = 20;
                            
                                            // Disable this property for performance gains in Strategy Analyzer optimizations
                            
                                            // See the Help Guide for additional information
                            
                                            IsInstantiatedOnEachOptimizationIteration   = true;
                            
                                          
                            
                                            EnumValue       = MyEnumOne.MyCustom2;
                            
                                        }
                            
                                    }
                            
                             
                            
                                    protected override void OnBarUpdate()
                            
                                    {
                            
                                    }
                            
                             
                            
                                    #region Use Case #4: Display "Friendly" enum values
                            
                             
                            
                                    [TypeConverter(typeof(FriendlyEnumConverter2))] // Converts the enum to string values
                            
                                    // Enums normally automatically get a combo box, but we need to apply this specific editor so default value is automatically selected
                            
                                    [PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")]
                            
                                    [Display(Name = "Friendly Enum", Order = 8, GroupName = "Use Case #4")]
                            
                                    public MyEnumOne EnumValue
                            
                                    { get; set; }
                            
                             
                            
                                    #endregion
                            
                                }
                            
                             
                            
                             
                            
                                #region Use Case #4: Display "friendly" enum values
                            
                                public enum MyEnumOne
                            
                                {
                            
                                    MyCustom1,
                            
                                    MyCustom2,
                            
                                    MyCustom3
                            
                                }
                            
                             
                            
                                // Since this is only being applied to a specific property rather than the whole class,
                            
                                // we don't need to inherit from IndicatorBaseConverter and we can just use a generic TypeConverter
                            
                                public class FriendlyEnumConverter2 : TypeConverter
                            
                                {
                            
                                    // Set the values to appear in the combo box
                            
                                    public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
                            
                                    {
                            
                                        List<string> values = new List<string>() { "My custom one", "My custom two", "My custom three" };
                            
                                      
                            
                                        // Instead of Print()
                            
                                        foreach(string val in values)
                            
                                        {
                            
                                            NinjaTrader.Code.Output.Process("val: " + val, PrintTo.OutputTab1);
                            
                                        }
                            
                             
                            
                                        return new StandardValuesCollection(values);
                            
                                    }
                            
                             
                            
                                    // map the value from "Friendly" string to MyEnumOne type
                            
                                    public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
                            
                                    {
                            
                                        string stringVal = value.ToString();
                            
                                      
                            
                                        // Instead of Print()
                            
                                        NinjaTrader.Code.Output.Process("stringVal0: " + stringVal, PrintTo.OutputTab1);
                            
                                      
                            
                                        switch (stringVal)
                            
                                        {
                            
                                            case "My custom one":
                            
                                                NinjaTrader.Code.Output.Process("stringValA: " + stringVal, PrintTo.OutputTab1);
                            
                                            return MyEnumOne.MyCustom1;
                            
                                            case "My custom two":
                            
                                                NinjaTrader.Code.Output.Process("stringValB: " + stringVal, PrintTo.OutputTab1);
                            
                                            return MyEnumOne.MyCustom2;
                            
                                            case "My custom three":
                            
                                                NinjaTrader.Code.Output.Process("stringValC: " + stringVal, PrintTo.OutputTab1);
                            
                                            return MyEnumOne.MyCustom3;
                            
                                        }
                            
                                        return MyEnumOne.MyCustom1;
                            
                                        // Instead of Print()
                            
                                        NinjaTrader.Code.Output.Process("stringVal1: " + stringVal, PrintTo.OutputTab1);
                            
                                    }
                            
                             
                            
                                    // map the MyEnumOne type to "Friendly" string
                            
                                    public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
                            
                                    {
                            
                                        MyEnumOne stringVal = (MyEnumOne) Enum.Parse(typeof(MyEnumOne), value.ToString());
                            
                                      
                            
                                        // Instead of Print()
                            
                                        NinjaTrader.Code.Output.Process("stringVal2: " + stringVal, PrintTo.OutputTab1);
                            
                                      
                            
                                        switch (stringVal)
                            
                                        {
                            
                                            case MyEnumOne.MyCustom1:
                            
                                                NinjaTrader.Code.Output.Process("stringValD: " + stringVal, PrintTo.OutputTab1);
                            
                                            return "My custom one";
                            
                                            case MyEnumOne.MyCustom2:
                            
                                                NinjaTrader.Code.Output.Process("stringValE: " + stringVal, PrintTo.OutputTab1);
                            
                                            return "My custom two";
                            
                                            case MyEnumOne.MyCustom3:
                            
                                                NinjaTrader.Code.Output.Process("stringValF: " + stringVal, PrintTo.OutputTab1);
                            
                                            return "My custom three";
                            
                                        }
                            
                                        return string.Empty;
                            
                                      
                            
                                        // Instead of Print()
                            
                                        NinjaTrader.Code.Output.Process("stringVal3: " + stringVal, PrintTo.OutputTab1);
                            
                                    }
                            
                             
                            
                                    // required interface members needed to compile
                            
                                    public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
                            
                                    { return true; }
                            
                             
                            
                                    public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
                            
                                    { return true; }
                            
                             
                            
                                    public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
                            
                                    { return true; }
                            
                             
                            
                                    public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
                            
                                    { return true; }
                            
                                }
                            
                                #endregion
                            
                            }
                            ​
                            Attached Files
                            Last edited by PaulMohn; 08-28-2024, 03:40 AM.

                            Comment


                              #15
                              Prints for the SampleStrategyTypeConverter script reduced to Use Case #4: Display "friendly" enum values,
                              with the Instance of the Strategy Class Object named: _SampleStrategyTypeConverter1 in
                              public class FriendlyEnumConverter2 : TypeConverter




                              Output:
                              Button1Label (State.SetDefaults) 1
                              Button1Label (State.SetDefaults) 1
                              Button1Label (State.SetDefaults) 1
                              stringVal2: MyCustom2
                              stringValE: MyCustom2
                              val: My custom one
                              Button1Label (TypeConverter): 1
                              val: My custom two
                              Button1Label (TypeConverter): 1
                              val: My custom three
                              Button1Label (TypeConverter): 1
                              Button1Label (State.SetDefaults) 1
                              Button1Label (State.SetDefaults) 1
                              stringVal2: MyCustom2
                              stringValE: MyCustom2
                              val: My custom one
                              val: My custom two
                              val: My custom three
                              Button1Label (TypeConverter): 1
                              stringVal0: My custom one
                              stringValA: My custom one
                              stringVal2: MyCustom1
                              stringValD: MyCustom1
                              stringVal0: My custom three
                              stringValC: My custom three
                              stringVal2: MyCustom3
                              stringValF: MyCustom3​
                              Script:
                              Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.


                              Code:
                              // https://forum.ninjatrader.com/forum/ninjatrader-8/strategy-development/1315837-how-to-get-the-enum-s-inputs-displayed-on-the-strategy-prope?p=1315985#post1315985
                              
                              // Copyright (C) 2018, NinjaTrader LLC <www.ninjatrader.com>.
                              
                              // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
                              
                              //
                              
                              #region Using declarations
                              
                              using NinjaTrader.Cbi;
                              
                              using NinjaTrader.Core.FloatingPoint;
                              
                              using NinjaTrader.Data;
                              
                              using NinjaTrader.Gui.Chart;
                              
                              using NinjaTrader.Gui.SuperDom;
                              
                              using NinjaTrader.Gui;
                              
                              using NinjaTrader.NinjaScript.DrawingTools;
                              
                              using NinjaTrader.NinjaScript.Indicators;
                              
                              using NinjaTrader.NinjaScript;
                              
                              using System.Collections.Generic;
                              
                              using System.Collections.ObjectModel;
                              
                              using System.Collections;
                              
                              using System.ComponentModel.DataAnnotations;
                              
                              using System.ComponentModel;
                              
                              using System.Globalization;
                              
                              using System.IO;
                              
                              using System.Linq;
                              
                              using System.Reflection;
                              
                              using System.Text;
                              
                              using System.Threading.Tasks;
                              
                              using System.Windows.Input;
                              
                              using System.Windows.Media;
                              
                              using System.Windows;
                              
                              using System.Xml.Serialization;
                              
                              using System;
                              
                              #endregion
                              
                               
                              
                              //This namespace holds strategies in this folder and is required. Do not change it.
                              
                              namespace NinjaTrader.NinjaScript.Strategies
                              
                              {
                              
                                  // Notes:
                              
                                  // Helper classes and type converters are defined below the indicator, separated by use case
                              
                                  // Property definitions are documented as necessary in the Properties region
                              
                                  // Debugging issues will likely require compiling NS in debug mode and attaching VS to ninjatrader.exe
                              
                                  // Setting breakpoints to examine values and seeing debug output that NT creates is helpful
                              
                                
                              
                                  public class _SampleStrategyTypeConverter1 : Strategy
                              
                                  {
                              
                                      protected override void OnStateChange()
                              
                                      {
                              
                                          if (State == State.SetDefaults)
                              
                                          {
                              
                                              Description                                 = @"Demonstrating using type converters to customize the Indicator property grid";
                              
                                              Name                                        = "_SampleStrategyTypeConverter1";
                              
                                              Calculate                                   = Calculate.OnBarClose;
                              
                                              EntriesPerDirection                         = 1;
                              
                                              EntryHandling                               = EntryHandling.AllEntries;
                              
                                              IsExitOnSessionCloseStrategy                = true;
                              
                                              ExitOnSessionCloseSeconds                   = 30;
                              
                                              IsFillLimitOnTouch                          = false;
                              
                                              MaximumBarsLookBack                         = MaximumBarsLookBack.TwoHundredFiftySix;
                              
                                              OrderFillResolution                         = OrderFillResolution.Standard;
                              
                                              Slippage                                    = 0;
                              
                                              StartBehavior                               = StartBehavior.WaitUntilFlat;
                              
                                              TimeInForce                                 = TimeInForce.Gtc;
                              
                                              TraceOrders                                 = false;
                              
                                              RealtimeErrorHandling                       = RealtimeErrorHandling.StopCancelClose;
                              
                                              StopTargetHandling                          = StopTargetHandling.PerEntryExecution;
                              
                                              BarsRequiredToTrade                         = 20;
                              
                                              // Disable this property for performance gains in Strategy Analyzer optimizations
                              
                                              // See the Help Guide for additional information
                              
                                              IsInstantiatedOnEachOptimizationIteration   = true;
                              
                                            
                              
                                              EnumValue       = MyEnumOne.MyCustom2;
                              
                                                
                              
                                              Button1Label    = "1";
                              
                                              Print("Button1Label (State.SetDefaults) " + Button1Label);
                              
                                          }
                              
                                      }
                              
                               
                              
                                      protected override void OnBarUpdate()
                              
                                      {
                              
                                      }
                              
                               
                              
                                      #region Use Case #4: Display "Friendly" enum values
                              
                               
                              
                                      [TypeConverter(typeof(FriendlyEnumConverter2))] // Converts the enum to string values
                              
                                      // Enums normally automatically get a combo box, but we need to apply this specific editor so default value is automatically selected
                              
                                      [PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")]
                              
                                      [Display(Name = "Friendly Enum", Order = 8, GroupName = "Use Case #4")]
                              
                                      public MyEnumOne EnumValue
                              
                                      { get; set; }
                              
                                
                              
                                      [NinjaScriptProperty]
                              
                                      [Display(Name="Label Button 1", Order=2, GroupName="Parameters")]
                              
                                      public string Button1Label
                              
                                      { get; set; }
                              
                               
                              
                                      #endregion
                              
                                  }
                              
                               
                              
                               
                              
                                  #region Use Case #4: Display "friendly" enum values6
                              
                                  public enum MyEnumOne
                              
                                  {
                              
                                      MyCustom1,
                              
                                      MyCustom2,
                              
                                      MyCustom3
                              
                                  }
                              
                               
                              
                                  // Since this is only being applied to a specific property rather than the whole class,
                              
                                  // we don't need to inherit from IndicatorBaseConverter and we can just use a generic TypeConverter
                              
                                  public class FriendlyEnumConverter2 : TypeConverter
                              
                                  {
                              
                                      /// INSTANCE OF THE STRATEGY CLASS OBJECT NAMED: _SampleStrategyTypeConverter1
                              
                                      _SampleStrategyTypeConverter1 strategyClassInstance = new _SampleStrategyTypeConverter1();
                              
                                    
                              
                                      // Set the values to appear in the combo box
                              
                                      public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
                              
                                      {
                              
                                          List<string> values = new List<string>() { "My custom one", "My custom two", "My custom three" };
                              
                                        
                              
                                          // Instead of Print()
                              
                                          foreach(string val in values)
                              
                                          {
                              
                                              NinjaTrader.Code.Output.Process("val: " + val, PrintTo.OutputTab1);
                              
                                          }
                              
                                        
                              
                                          NinjaTrader.Code.Output.Process("Button1Label (TypeConverter): "
                              
                                                                          + strategyClassInstance.Button1Label, PrintTo.OutputTab1);
                              
                               
                              
                                          return new StandardValuesCollection(values);
                              
                                      }
                              
                               
                              
                                      // map the value from "Friendly" string to MyEnumOne type
                              
                                      public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
                              
                                      {
                              
                                          string stringVal = value.ToString();
                              
                                        
                              
                                          // Instead of Print()
                              
                                          NinjaTrader.Code.Output.Process("stringVal0: " + stringVal, PrintTo.OutputTab1);
                              
                                        
                              
                                          switch (stringVal)
                              
                                          {
                              
                                              case "My custom one":
                              
                                                  NinjaTrader.Code.Output.Process("stringValA: " + stringVal, PrintTo.OutputTab1);
                              
                                              return MyEnumOne.MyCustom1;
                              
                                              case "My custom two":
                              
                                                  NinjaTrader.Code.Output.Process("stringValB: " + stringVal, PrintTo.OutputTab1);
                              
                                              return MyEnumOne.MyCustom2;
                              
                                              case "My custom three":
                              
                                                  NinjaTrader.Code.Output.Process("stringValC: " + stringVal, PrintTo.OutputTab1);
                              
                                              return MyEnumOne.MyCustom3;
                              
                                          }
                              
                                          return MyEnumOne.MyCustom1;
                              
                                          // Instead of Print()
                              
                                          NinjaTrader.Code.Output.Process("stringVal1: " + stringVal, PrintTo.OutputTab1);
                              
                                      }
                              
                               
                              
                                      // map the MyEnumOne type to "Friendly" string
                              
                                      public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
                              
                                      {
                              
                                          MyEnumOne stringVal = (MyEnumOne) Enum.Parse(typeof(MyEnumOne), value.ToString());
                              
                                        
                              
                                          // Instead of Print()
                              
                                          NinjaTrader.Code.Output.Process("stringVal2: " + stringVal, PrintTo.OutputTab1);
                              
                                        
                              
                                          switch (stringVal)
                              
                                          {
                              
                                              case MyEnumOne.MyCustom1:
                              
                                                  NinjaTrader.Code.Output.Process("stringValD: " + stringVal, PrintTo.OutputTab1);
                              
                                              return "My custom one";
                              
                                              case MyEnumOne.MyCustom2:
                              
                                                  NinjaTrader.Code.Output.Process("stringValE: " + stringVal, PrintTo.OutputTab1);
                              
                                              return "My custom two";
                              
                                              case MyEnumOne.MyCustom3:
                              
                                                  NinjaTrader.Code.Output.Process("stringValF: " + stringVal, PrintTo.OutputTab1);
                              
                                              return "My custom three";
                              
                                          }
                              
                                          return string.Empty;
                              
                                        
                              
                                          // Instead of Print()
                              
                                          NinjaTrader.Code.Output.Process("stringVal3: " + stringVal, PrintTo.OutputTab1);
                              
                                      }
                              
                               
                              
                                      // required interface members needed to compile
                              
                                      public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
                              
                                      { return true; }
                              
                               
                              
                                      public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
                              
                                      { return true; }
                              
                               
                              
                                      public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
                              
                                      { return true; }
                              
                               
                              
                                      public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
                              
                                      { return true; }
                              
                                  }
                              
                                  #endregion
                              
                              }
                              ​
                              source:
                              https://stackoverflow.com/a/12997745/10789707​

                              Class Object named MyClass:
                              Code:
                                  public class MyClass
                                  {
                                      
                                  }
                              Instance of the Class Object MyClass:
                              Code:
                                  MyClass cls = new MyClass();
                              Instance of the class object MyClass reused in another class (Program):
                              Code:
                                  public class Program
                                  {
                                      MyClass cls = new MyClass();      
                                  }
                              Attached Files
                              Last edited by PaulMohn; 08-28-2024, 03:51 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Yesterday, 05:17 AM
                              0 responses
                              62 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              134 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              75 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              45 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              50 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X