Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How do I implement Decorated Enums

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

    #16
    Hello,

    Thank you for the reply.

    There are a few different fonts used through the platform and in the property grid. These are skin dependent, for this question I would suggest performing a test with the skin you are using.

    The short answer is it looks like Arial is being used. The long answer is that the fonts can be found in the file:

    Documents\NinjaTrader 8\templates\Skins\Name of Skin being used\BluePrint.xaml

    If you search the file for " Fonts and Margins " the lines below describe the various fonts used.

    It looks like there is a font used for the Headers in the property grid which is noted in the files comments.

    Code:
    <!-- Header 3 (Used for section headers in property grids such as the Data Series window Properties  -->
    	<system:Double			x:Key="FontHeaderLevel3Height">12</system:Double>
    	<FontFamily				x:Key="FontHeaderLevel3Family">Arial</FontFamily>
    	<FontStyle				x:Key="FontHeaderLevel3Style">Normal</FontStyle>
    	<FontWeight				x:Key="FontHeaderLevel3Weight">Bold</FontWeight>
    	<SolidColorBrush		x:Key="FontHeaderLevel3Brush" Color="#FFCCCCCC" po:Freeze="true"/>
    	<system:Double			x:Key="FontHeaderLevel3Margin">9</system:Double>

    There are also fonts for controls like dropdown boxes, check boxes and others :


    Code:
    <!-- Fonts for text labels used to label controls (check boxes, dropdown menus, etc.) -->
    	<system:Double			x:Key="FontLabelHeight">12</system:Double>
    	<FontFamily				x:Key="FontLabelFamily">Arial</FontFamily>
    	<FontStyle				x:Key="FontLabelStyle">Normal</FontStyle>
    	<FontWeight				x:Key="FontLabelWeight">Regular</FontWeight>
    	<SolidColorBrush		x:Key="FontLabelBrush" Color="#FFCCCCCC" po:Freeze="true"/>


    I would suggest to edit the file for the skin you are using, and set some specific colors such as lime green to locate where in the platform that font is being used. This would allow you to see specifically what font is used for the item you are wanting a font from.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #17
      ChelseaB and MichaelM MVPs
      Unsuitable
      NinjaTrader Ecosystem Vendor - Ocean Trading Indicators

      Comment


        #18
        Originally posted by NinjaTrader_ChelseaB View Post
        Hello KhaosTrader,

        A custom type converter would be necessary to have custom display attributes in the properties menu. However, custom type converters are not supported by NinjaTrader Support.

        I have submitted a feature request to our development on your behalf to allow for friendly enum display names. It is up to the NinjaTrader Development to decide if and when a feature request will be implemented.

        That said, NinjaTrader_MichaelM and I were able to find a way to do this and I want to share our work with you.
        This example is not supported by the NinjaTrader Support as this uses unsupported methods to achieve this goal (custom type converters). In the process of determining the issue, we were able to workout a non supported solution I wish to share with you.

        Code:
        public enum AnEnumList
        {
        [Description("Enum 1 friendly name")]
        Enum1,
        [Description("Enum 2 friendly name")]
        Enum2,
        [Description("Enum 3 friendly name")]
        Enum3,
        }
        Code:
        public class EnumDescriptionConverter : EnumConverter
        {
        private Type enumType;
        
        public EnumDescriptionConverter(Type type) : base(type)
        {
        enumType = type;
        }
        
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type srcType)
        {
        return srcType == typeof(string);
        }
        
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destType)
        {
        return destType == typeof(string);
        }
        
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
        foreach (System.Reflection.FieldInfo fi in enumType.GetFields())
        {
        DescriptionAttribute dna = (DescriptionAttribute)Attribute.GetCustomAttribute(fi, typeof(DescriptionAttribute));
        if (dna != null && (string)value == dna.Description)
        return Enum.Parse(enumType, fi.Name);
        }
        return Enum.Parse(enumType, (string)value);
        }
        
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
        {
        System.Reflection.FieldInfo fi = enumType.GetField(value.ToString());
        DescriptionAttribute dna = (DescriptionAttribute) Attribute.GetCustomAttribute(fi, typeof(DescriptionAttribute));
        if(dna != null)
        return dna.Description;
        else
        return value.ToString();
        }
        
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
        List<string> values = new List<string>();
        foreach (var v in Enum.GetValues(enumType))
        {
        System.Reflection.FieldInfo fi = enumType.GetField(v.ToString());
        DescriptionAttribute dna = (DescriptionAttribute)Attribute.GetCustomAttribute(fi, typeof(DescriptionAttribute));
        if (dna != null)
        values.Add(dna.Description);
        else
        values.Add(v.ToString());
        }
        return new StandardValuesCollection(values);
        }
        }
        Code:
        [NinjaScriptProperty]
        [TypeConverter(typeof(EnumDisplayAttributeExampleTools.EnumDescriptionConverter))]
        [PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")]
        [Display(Name = "My Enum List", Order = 0, GroupName = "Parameters", Description = "A list of enums")]
        public EnumDisplayAttributeExampleTools.AnEnumList MyEnumList
        { get; set; }
        Hello, I tried to put the TypeConverter into a file (.dll) as a kind of extension and include it via Reference. There are no errors, but the TypeConverter is not used. How can I write the TypeConverter into a custom file and use it via Reference?


        Attached Files
        Last edited by sidlercom80; 04-20-2022, 03:32 AM.
        sidlercom80
        NinjaTrader Ecosystem Vendor - Sidi Trading

        Comment


          #19
          Hello sidlercom80,

          You need to change how you used the type converter, you have TypeOf(...) which is a cast to a type. You need to fill in the type as a string as the type is in the assembly:

          Code:
          [TypeConverter("EnumDisplayAttributeExampleTools.EnumDescriptionConverter")]
          I tried that as a compiled dll and see the friendly enum working.
          JesseNinjaTrader Customer Service

          Comment


            #20
            Hi _Jesse, thank you for your answer. Did you do this through the export process, or externally as I would like? I create a custom .dll in an external directory via VS and then want to include this .dll by reference.
            Click image for larger version

Name:	Screenshot_1.jpg
Views:	184
Size:	3.9 KB
ID:	1198223
            I do not want to do this via the NT export process. I created this EnumLibExample.dll only via VS and copied it into the NT directory and referenced it.
            Unfortunately, this does not work for me, but why?

            Click image for larger version

Name:	Screenshot_3.jpg
Views:	187
Size:	87.2 KB
ID:	1198224
            sidlercom80
            NinjaTrader Ecosystem Vendor - Sidi Trading

            Comment


              #21
              Hello sidlercom80,

              In the image you provided the namespace is not correct, you need to use the correct namespace to where you have the type converter in that file. The code I provided in post 19 has the namespace you used in the files you provided in post 18.

              In the new image it looks like you have the type converter commented out as well.

              I would suggest to revert back to the tests you uploaded in post 18 and try exporting that from the platform first to verify you have it working, at that point you could try using visual studio.


              JesseNinjaTrader Customer Service

              Comment


                #22
                Hi _Jesse, I can't get it to run. If I create the .dll via the export from NT, it does not work either. What should be the correct name, based on my example here?

                This is in the .dll file I have referenced.

                Click image for larger version

Name:	Screenshot_1.jpg
Views:	178
Size:	75.1 KB
ID:	1198251
                this file is in the /bin/custom folder:

                Click image for larger version

Name:	Screenshot_2.jpg
Views:	181
Size:	4.9 KB
ID:	1198249
                Click image for larger version

Name:	Screenshot_4.jpg
Views:	163
Size:	7.6 KB
ID:	1198252

                Click image for larger version

Name:	Screenshot_3.jpg
Views:	185
Size:	61.4 KB
ID:	1198250
                sidlercom80
                NinjaTrader Ecosystem Vendor - Sidi Trading

                Comment


                  #23
                  Hello sidlercom80,

                  From the image it looks like the names changed again so its a little difficult to track what may be going wrong. I will revert to the samples you provided in post 18, that was actual code so I was able to test it.

                  In what you previously provided you have EnumDisplayAttributeExample Indicator. Inside that indicator you had:

                  Code:
                  [NinjaScriptProperty]
                  [TypeConverter("EnumDisplayAttributeExampleTools.En umDescriptionConverter")]
                  [PropertyEditor("NinjaTrader.Gui.Tools.StringStanda rdValuesEditorKey")]
                  [Display(Name = "My Enum List", Order = 0, GroupName = "Parameters", Description = "A list of enums")]
                  public EnumExample.AnEnumList MyEnumList
                  { get; set; }
                  The only change I made was the type converter to being a string. The type converter points to the namespace and class name you had used in the EnumConverterTest file:

                  Code:
                  namespace [B]EnumDisplayAttributeExampleTools[/B]
                  {
                  public class [B]EnumDescriptionConverter [/B]: EnumConverter

                  The namespace was EnumDisplayAttributeExampleTools and the converter name was EnumDescriptionConverter. Based on that detail the type converter needs to be:
                  Code:
                  [TypeConverter("EnumDisplayAttributeExampleTools.EnumDescriptionConverter")]
                  After making that change I could export the two files as a compiled assembly, exclude the original source code and then import the compiled assembly. I was able to see the converter being used.

                  JesseNinjaTrader Customer Service

                  Comment


                    #24
                    Hi _Jesse, you misunderstood me! I want to leave the indicator file "EnumDisplayAttributeExample" in the indicator directory. I want to create the "EnumDescriptionConverter " outside NT and NOT import it via import process, but only copy it into the /bin/custom directory and reference it.
                    In your attempts, you exported the index file and the addon file together via the export process into a .zip file and then imported it again via the import process. I have no problems with this either. But creating the "EnumDescriptionConverter " outside of NT and WITHOUT .zip import does not work.
                    sidlercom80
                    NinjaTrader Ecosystem Vendor - Sidi Trading

                    Comment


                      #25
                      Hello sidlercom80,

                      I don't see that working to reference it in that way from the compiled assembly. You would instead include it with the assembly because it is a requirement for that assembly and the properties inside it. Making shared assemblies with type converters also does not work with how they are loaded. For your use case it would be suggested to include a copy of the type converter in the dll inside a custom namespace for that script to use. That would avoid conflicts in case this was part of multiple items that used the same type converter, other items would presumably have their own namespace for their converters.



                      JesseNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by AttiM, 02-14-2024, 05:20 PM
                      11 responses
                      184 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by fernandobr, Today, 09:11 AM
                      1 response
                      3 views
                      0 likes
                      Last Post NinjaTrader_Erick  
                      Started by timmbbo, Today, 08:59 AM
                      1 response
                      3 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by KennyK, 05-29-2017, 02:02 AM
                      2 responses
                      1,281 views
                      0 likes
                      Last Post marcus2300  
                      Started by itrader46, Today, 09:04 AM
                      1 response
                      6 views
                      0 likes
                      Last Post NinjaTrader_Clayton  
                      Working...
                      X