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

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.
    JesseNinjaTrader Customer Service

    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 cre8able, Yesterday, 09:15 PM
        2 responses
        14 views
        0 likes
        Last Post cre8able  
        Started by Trader146, Today, 09:17 PM
        0 responses
        6 views
        0 likes
        Last Post Trader146  
        Started by ttrader23, 05-08-2024, 09:04 AM
        9 responses
        43 views
        0 likes
        Last Post ttrader23  
        Started by ZeroKuhl, Yesterday, 04:31 PM
        8 responses
        46 views
        0 likes
        Last Post ZeroKuhl  
        Started by reynoldsn, Today, 07:04 PM
        0 responses
        11 views
        0 likes
        Last Post reynoldsn  
        Working...
        X