Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom properties

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

    Custom properties

    where can I find sample or help on custom properties e.g.

    type = 1 or 2

    hide a property based on another property

    I did find this last year but not this year?

    #2
    Hello dibDab,

    Thank you for your post.

    I believe you are referring to the following reference sample from the help guide:There are a few different use cases in that script, including how to show/hide properties based on secondary input and how to display friendly enum values.

    Please let us know if we may be of further assistance.

    Comment


      #3
      ok thanks. I had a look at SampleIndicatorTypeConverter

      but not sure what "Reflection to copy Collection to new assembly" does or can I ignore it?

      Comment


        #4
        Hello dibDab,

        Thank you for your reply.

        That portion of the script is necessary. Sometimes NinjaTrader clones an existing instance of a script to a new instance, such as when you right-click a chart and select Reload NinjaScript. What would happen is that portion of code (from lines 144 to 175 in the SampleIndicatorTypeConverter script) would use reflection to copy the property values to the new instance that is created. For more information on instances, please see the NinjaScript Lifecycle page here:


        Please let us know if we may be of further assistance.

        Comment


          #5
          ok thanks, the attached has a few problems, do you have an update? SampleIndicatorTypeConverter_NT8.zip

          Click image for larger version  Name:	image.png Views:	0 Size:	5.5 KB ID:	1269779

          Comment


            #6
            Originally posted by dibDab View Post
            ok thanks, the attached has a few problems, do you have an update? SampleIndicatorTypeConverter_NT8.zip

            Click image for larger version Name:	image.png Views:	0 Size:	5.5 KB ID:	1269779
            Your attachment seems to be the same as the example from the help guide, which I am able to import and compile successfully without errors:


            Are you also able to import this script and compile it successfully? Have you made changes to this script that result in the errors? If possible, please provide a screenshot showing the full error information, including the script name and the line number the error is referring to. I also suggest reviewing the lines mentioned in the errors to narrow down the location of the code that might be causing the errors.

            I look forward to your reply.

            Comment


              #7
              my error, apologies

              Comment


                #8
                SampleIndicatorTypeConverter very useful learning aid

                Comment


                  #9
                  is this ok?

                  to create long/short combo box property ...

                  I added this property to public class myAAXX10002Indicator : Indicator

                  Code:
                      [TypeConverter(typeof(myAAXX10002BoolConverter))] // Converts the bool to string values
                      [PropertyEditor("NinjaTrader.Gui.Tools.StringStandardValuesEditorKey")] // Create the combo box on the property grid
                      [Display(Name = "trading Mode", Order = 2, GroupName = "1. Setup")]
                      public bool tradingMode //set to true in State.SetDefaults
                      { get; set; }
                  and added this class to namespace NinjaTrader.NinjaScript.Indicators

                  Code:
                      public class myAAXX10002BoolConverter : TypeConverter
                      {
                          public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
                          {
                              List<string> values = new List<string>() { "LONG", "SHORT" };
                  
                              return new StandardValuesCollection(values);
                          }
                  
                          public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
                          {
                              return value.ToString() == "LONG" ? true : false;
                          }
                  
                          public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
                          {
                              return (bool) value ? "LONG" : "SHORT";
                          }
                  
                          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; }
                      }

                  Comment


                    #10
                    Hello dibDab,

                    Thank you for your note.

                    Your snippets seem to be okay and follow the example from the sample script. Please test your script by adding print statements that print the value of tradingMode while the script is running and ensure that the values are matching based on whether the box is checked/unchecked. Also be sure to check for any error messages on the Log tab of the Control Center related to your script. Otherwise, I don't currently see any issues based on what you have shared.

                    Please feel free to reach out with any additional questions or concerns.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    577 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    334 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    101 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    553 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    551 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X