Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Class Heirarchy With Indicator in Class Name causes code generation.

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

    Class Heirarchy With Indicator in Class Name causes code generation.

    I have a setup similar to the following code snippet that triggers Indicator code generation by NinjaTrader despite not actually deriving from Indicator class.

    Code:
        public class IndicatorSomethingOrOther
        {
    
        }
    
        public class Test: IndicatorSomethingOrOther
        {
    
        }
    The file that contains that code, despite the folder in NinjaTrader I put it in, will add the indicator generating code for Test class. I was under the assumption that only classes derived from Indicator class itself had code generated. Why is the above code causing the code generation?

    Putting the code in another namespace doesn't stop the code from generating. Making the class Test private instead of public does prevent it from having NinjaTrader auto generate the code.
    Last edited by ntbone; 07-01-2020, 01:02 AM.

    #2
    Hello ntbone,

    If the parent class inheriting from indicator at all that will generally happen.

    If you used Indicator in the name that's likely also a problem, you could use a less generic name. Indicator is being looked for in the indicator files as a means of generation.

    If you have this in the indicators folder and it is not an indicator you can move the parent class from the indicators folder to the addons folder.

    Outside of these observations I couldn't really suggest much here as we don't support custom inheritance like this, I would suggest to instead create standard classes that inherits from the NinjaScript type like a standard indicator does. If you need to share some common code you could use a partial class for the type or a custom class as a private variable instead of custom inheritance.




    Please let me know if I may be of further assistance.

    Comment


      #3
      Try
      Code:
        public class Test
      : IndicatorSomethingOrOther     {      }

      Comment


        #4
        To NinjaTrader_Jesse's comments, the above code has no references to Indicator class at all. It simply has Indicator in the name. I wouldn't call it "custom" inheritance. I had tried putting the code in a different folder but that folder name also had the word Indicator in it.

        MojoJojo, your idea worked great.

        For any looking for what works and what doesn't here's a summary.

        Code That Causes Generation

        Any class that inherits from another class that has the word "indicator" in it. Its case insensitive and it doesn't matter where the word appears in the name. The class would be inside a file in the Indicators folder or any custom folder that has "Indicator" in the name. It doesn't matter what namespace the classes are in.

        Code That Won't Cause Generation
        • Aside from removing the word Indicator, put the code in a custom folder in NinjaTrader outside of the Indicators folder and make sure it doesn't include the word "Indicator" in the name of the folder.
        • Inherit from the class by putting the inherited name on a second line, like MojoJojo has done.

        This can be used as a trick if you want to do add layers of inheritance to your Indicator classes (although this is probably not officially supported). Consider the following.
        Code:
            class A: Indicator
            {
        
            }
        
            class B: A
            {
        
            }
        B will not have code generated for it, but A will. However if you rename class A to be

        Code:
            public class AIndicator : Indicator
            {
        
            }
        
            public class B : AIndicator
            {
        
            }
        Both AIndicator and B will get code generated for them.
        Last edited by ntbone; 07-01-2020, 01:11 PM.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        649 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        370 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        576 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X