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

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.
    Emily C.NinjaTrader Customer Service

    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.
        Emily C.NinjaTrader Customer Service

        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.
            Emily C.NinjaTrader Customer Service

            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.
                    Emily C.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by bc24fl, 08-30-2019, 01:58 PM
                    4 responses
                    259 views
                    0 likes
                    Last Post PaulMohn  
                    Started by sugalt, Today, 04:02 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post sugalt
                    by sugalt
                     
                    Started by tradingnasdaqprueba, 04-09-2024, 09:52 AM
                    6 responses
                    30 views
                    0 likes
                    Last Post tradingnasdaqprueba  
                    Started by PaulMohn, Today, 02:06 AM
                    1 response
                    8 views
                    0 likes
                    Last Post PaulMohn  
                    Started by Mindset, Today, 01:27 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Working...
                    X