Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on try to add parameter

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

    Error on try to add parameter

    I am trying to add a parameter to a user Ninja 8 indicator but get a "class, delagate, enum, interface struct expected" error. Not sure what it is telling me it doesn't like about it other than it is clearly not happy. I copied the statements from an exiting indicator that compiles normally.

    ----------------------
    region Properties

    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Smooth", GroupName = "NinjaScriptParameters", Order = 0)]
    public int Smooth
    { get; set; }

    #endregion
    ------------------

    Any idea what I am doing wrong? After 10 years of Ninja 7 still learning about Ninja 8 so most likely a rookie error by me.


    Screen shot from the editor.
    Click image for larger version  Name:	image.png Views:	0 Size:	151.0 KB ID:	1233099


    Last edited by ct; 01-29-2023, 08:28 AM.

    #2
    Hello ct,

    Move your property declaration inside of your indicator class. (Between the curly braces for the class)

    See the NinjaScript Editor 401 training video if you are not familiar with scope.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chesea

      That did the trick. I get to wear the dunce cap now for a while. Double rookie error. I thought I tried that but i didn't. You are an absolute star.

      Many thanks.

      Cheers from the far side of the planet.

      Comment


        #4
        I have this

        Code:
        namespace NinjaTrader.NinjaScript.[B]Strategies[/B]
        {
        [TypeConverter("NinjaTrader.NinjaScript.Strategies.MyXConverter")]​​
        outside the class scope as per the given example Sample Indicator TypeConverter Ninjatrader

        https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?using_a_typeconverte r_to_custo.htm

        https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?using_a_typeconverter_to_custo.htm


        It compiles without error but then as soon as I start to edit the remaining code it throws this compile error:

        NinjaScript File Error Code Line Column
        MyXConverterStrat.cs Class, delegate, enum, interface, or struct expected. 82 89

        If I place it in the class scope as

        Code:
        //This namespace holds Strategies in this folder and is required. Do not change it.
        namespace NinjaTrader.NinjaScript.Strategies
        {
        public class MyXConverterStrat: Strategy
        {
        [TypeConverter("NinjaTrader.NinjaScript.Strategies.MyXConverter")]​
        it thows this other compile error:

        ​NinjaScript File Error Code Line Column
        MyXConverterStrat.cs Class member declaration expected. 87 89
        What is causing the 1st error? What is the fix to the 1st error other than the class scope suggestion?

        Last edited by PaulMohn; 08-23-2024, 10:27 AM.

        Comment


          #5
          Hello PaulMohn,

          The attribute should be one line above the class declaration (as in the first code suggestion).

          However, where is the typeconverter method declared?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Do you mean the typeconverter in the separate class?

            This?
            MyXConverterStrat strategy = component as MyXConverterStrat; // need the same name as the Class name

            Code:
            #region ConverterStuff
                
                public class MyXConverter: StrategyBaseConverter
                {
                    public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs)
                    {
                        MyXConverterStrat strategy = component as MyXConverterStrat; // need the same name as the Class name
            
                        PropertyDescriptorCollection propertyDescriptorCollection = base.GetPropertiesSupported(context)
                                                                                    ? base.GetProperties(context, component, attrs)
                                                                                    : TypeDescriptor.GetProperties(component, attrs);
            
                        if (strategy == null || propertyDescriptorCollection == null)
                            return propertyDescriptorCollection;
                            
            
                        PropertyDescriptor UpSoundFile            = propertyDescriptorCollection["UpSoundFile"];
                        
                            
                        // remove removable properties first
                        
                        propertyDescriptorCollection.Remove(UpSoundFile);
            
                        // Add back in if...
                                    
                        if (strategy.MyX())
                        {
                            propertyDescriptorCollection.Add(UpSoundFile);                                
                        }
                    
                        return propertyDescriptorCollection;
                    }
                    
                    // Important:  This must return true otherwise the type convetor will not be called
                    public override bool GetPropertiesSupported(ITypeDescriptorContext context)
                    { return true; }
                }        
                #endregion
            }​
            ​​

            I checked both the sample and PaulH example

            Sample Indicator TypeConverter
            https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?using_a_typeconverter_to_custo.htm

            ColorThePlot
            https://ninjatraderecosystem.com/user-app-share-download/colortheplot/

            Comment


              #7
              Hello PaulMohn,

              The converter class name is not the same as the indicator class name in SampleIndicatorTypeConverter.
              The indicator class name is SampleIndicatorTypeConverter, the converter class name is MyConverter. These are not the same name.

              The converter class name is not the same as the indicator class name in ColorThePlot.
              The indicator class name is ColorThePlot, the converter class name is ColorThePlotConverter. These are not the same name.

              But I am asking where MyXConverter is declared. Is this declared within the scope of the NinjaTrader.NinjaScript.Namespace? Did you declared it within the scope of the MyXConverter class?
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Yes, I have same as this, in a separate class within the scope/brackets of the namespace NinjaTrader.NinjaScript.Strategies

                Code:
                namespace NinjaTrader.NinjaScript.Strategies
                {
                    [TypeConverter("NinjaTrader.NinjaScript.Strategies.MyXConverter")]​
                
                    public class MyXConverterStrat : Strategy
                    {​
                        ...
                        public bool MyX()
                        {
                            if(Cond0())
                            {
                                 return true;
                             }
                                
                             return false;
                          }
                      ...
                    }
                
                
                    public class MyXConverter: StrategyBaseConverter
                    {
                        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs)
                        {
                            MyXConverterStrat strategy = component as MyXConverterStrat; // need the same name as the Class name
                
                            PropertyDescriptorCollection propertyDescriptorCollection = base.GetPropertiesSupported(context)
                                                                                        ? base.GetProperties(context, component, attrs)
                                                                                        : TypeDescriptor.GetProperties(component, attrs);
                
                            if (strategy == null || propertyDescriptorCollection == null)
                                return propertyDescriptorCollection;
                                
                
                            PropertyDescriptor UpSoundFile            = propertyDescriptorCollection["UpSoundFile"];
                            
                                
                            // remove removable properties first
                            
                            propertyDescriptorCollection.Remove(UpSoundFile);
                
                            // Add back in if...
                                        
                            if (strategy.MyX())
                            {
                                propertyDescriptorCollection.Add(UpSoundFile);                                
                            }
                        
                            return propertyDescriptorCollection;
                        }
                        
                        // Important:  This must return true otherwise the type convetor will not be called
                        public override bool GetPropertiesSupported(ITypeDescriptorContext context)
                        { return true; }
                    }       
                
                }​​

                Comment


                  #9
                  Hello PaulMohn,

                  Try using a different name for the converter class and reference that name in the attribute.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    What attribute? Example?

                    SampleIndicatorTypeConverter converter class name == SampleIndicatorTypeConverter
                    MyConverter indicator class name == MyConverter

                    ColorThePlotConverter converter class name == ColorThePlotConverter
                    ColorThePlot indicator class name == ColorThePlot​

                    MyXConverter converter class name == MyXConverter
                    MyXConverterStrat strategy class name == MyXConverterStrat​​

                    Comment


                      #11
                      Hello PaulMon,

                      The attribute is above the strategy class definition.

                      [TypeConverter("NinjaTrader.NinjaScript.Strategies. ADifferentNameHere")]​
                      public class MyXConverterStrat : Strategy
                      {
                      }

                      In post # 4 you are showing the strategy class name is MyXConverter.
                      If I place it in the class scope as

                      Code://This namespace holds Strategies in this folder and is required. Do not change it.
                      namespace NinjaTrader.NinjaScript.Strategies
                      {
                      public class MyXConverter: Strategy
                      {
                      [TypeConverter("NinjaTrader.NinjaScript.Strategies. MyXConverter")]​

                      If you've changed this to MyXConverterStrat this should be fine.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Ah yes apologies, that was copy paste and editing in the post, but on my side the MyXConverterStrat was correct as the strategy name.

                        I think I found the issue. Somehow there was an extra character likely resulting from copy pasting:


                        Click image for larger version  Name:	extrachar.png Views:	0 Size:	36.4 KB ID:	1315476



                        Click image for larger version  Name:	extrachar1.png Views:	0 Size:	21.6 KB ID:	1315477 ​ ZERO WIDTH SPACE

                        ​ U+200B ZERO WIDTH SPACE, copy and paste, unicode character symbol info, commonly abbreviated ZWSP, this character is intended for invisible word separation and for line break control; it has no width, but its presence between two characters does not prevent increased letter spacing in justification


                        It seems to be working now that I deleted it.
                        How do you check for these extra char issue in the ninjascript editor?

                        Comment


                          #13
                          Hello PaulMohn,

                          I'm not aware of a way to check these in the NinjaScript Editor.

                          But if you paste into notepad and then copy it again that might remove hidden characters.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Ok, can this checking feature be added to the next Ninjascript Editor Update?

                            Comment


                              #15
                              Hello PaulMohn,

                              I can submit a feature request, but I cannot say it will be in the next NinjaTrader release.

                              We receive many requests and cannot reasonably implement all requested features or changes. Interest is tracked internally and if enough interest is tracked, it would be weighed against how feasible it would be to make those changes to consider implementing, so we cannot offer an ETA or promise of fulfillment.

                              When new features are implemented, they will be listed in the Release Notes page of the Help Guide. The ID number may be different than the internal feature request tracking ID, but the description of the feature will let you know if that feature has been implemented.

                              Release Notes - https://ninjatrader.com/support/help...ease_notes.htm
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              85 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              47 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              29 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              32 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              67 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X