Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Polymorphism Auto Generated Code Issue

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

    Polymorphism Auto Generated Code Issue

    I've built a large framework on top in ninjatrader. Some of my indicators require many levels of inheritance.

    It works just fine, however I recently noticed that if there have been more then 2 levels of inheritance on an indicator then the auto generated code doesn't update properly.

    Specifically let's say C inherits from B which inherits from A. If I add a new property to C, the auto generated code won't have the new property. Same goes for me adding a property to B (it won't show up in Cs properties in that case).

    This wouldn't be a bit deal if it didn't affect caching and loading in my workspace.

    My code is sensitive, but if needed I can give enough context to generate my exact issue.

    #2
    Hello Jaggy,

    Welcome to the NinjaTrader forums!

    Unfortunately, NinjaTrader cannot support inheritance with Indicators, Strategies, or any of the other provided script types, other than custom addon classes that open in their own window outside of the structures of NinjaTrader windows.

    This will break the NinjaTrader generated code for method overloads, and will also break optimizations and property grids.

    Two alternatives would be:
    1. Use Partial Classes within Indicators or Strategies namespace for your custom shared methods. Partial classes are not initialized as their own object but as an extensions of the Indicator class and may be able to support inheritance.

      Below is a publicly available to the Microsoft documentation.
      https://docs.microsoft.com/en-us/dot...es-and-methods

      In the code breaking changes of the NinjaTrader 8 Help Guide, see the heading 'Partial Classes (Porting methods and properties from UserDefinedMethods.cs)'.
      https://ninjatrader.com/support/help...hangesOverview
      .
    2. Use a Static class method in a custom namespace, and pass any objects to the method, including 'this' meaning the entire indicator instance to the method for manipulation.

      Below is a link to an example using undocumented code of static classes.
      https://ninjatrader.com/support/foru...245#post712245

      As a heads up, running logic in a static method is generally fine. Storing values in static methods to communicate between scripts may work in real-time, but cannot be backtested.
    Last edited by NinjaTrader_ChelseaB; 12-08-2020, 03:10 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the response, but if that's the case why does this post imply the opposite? (Link is in the this word in that question)

      Comment


        #4
        Hello Jaggy,

        Are you referring to post # 8?

        After some testing, I have found that the way NinjaTrader instantiates objects in the runtime is out of the user's control. We do not have access to the logic that calls 'new' on the constructor, therefore we can not directly instantiate a child class from the NinjaTrader generated class that inherits the Strategy or Indicator base class. The example below does create an instance of 'MyStrategy' but it does so after making an instance of the 'MyStrategy' base class.

        I would recommend using a partial class as a different approach to separate your logic. You will have access to all methods and properties of the partial class inside of your main script. You may extend the Strategy or Indicator class in partial classes. All you will have to do is design your other NinjaScripts to access the data from this indicator. Please see the attached .zip file for a working example.
        https://ninjatrader.com/support/foru...332#post803332

        This basically describing how NinjaTrader on the backend is creating an instance of the strategy. The Abstract approach interferes with this, direct inheritance with a Strategy interferes with this.

        Further, ChrisL is suggesting that a partial class be used to extend the methods. This is what I am describing to you in post #2.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Actually post number 1 and 2, in post 1 the user gives the example of a base class (MyBaseClass) inheriting from strategy, and that another class is inheriting from that (MyStrategy).

          In post 2 the response says polymorphism is supported and doesn't point out any issues with the original posters example. I've done this multiple times myself and it's worked just fine, it's just not working now multiple layers deep.

          Comment


            #6
            Hello Jaggy,

            Unfortunately, that was said without testing and was corrected in a later post. ChrisL does have a better understanding of why this causes issues now.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Can I get a tracking number on the issue for this to be implemented? NT8 is a great platform, but this is a core feature for the work I do given the amount reused and universal concepts.

              Comment


                #8
                Hello Jaggy,

                As there are two working alternative solutions to share methods between classes, no feature request has been made to allow inheritance that I can find in our system.

                I will submit your request for the development to consider. Once I have a tracking ID for this I will post in this thread for future reference.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I appreciate it, thank you for clarifying this.

                  Comment


                    #10
                    Hello Jaggy,

                    Thank you for your patience.

                    Your request is being tracked under the number SFT-5158.

                    As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted in the Release Notes page of the Help Guide.

                    Release Notes — https://ninjatrader.com/support/help...ease_notes.htm

                    Please let us know if we may be of further assistance to you.
                    Kate W.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by frankthearm, Today, 09:08 AM
                    5 responses
                    14 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by jeronymite, 04-12-2024, 04:26 PM
                    3 responses
                    43 views
                    0 likes
                    Last Post jeronymite  
                    Started by yertle, Today, 08:38 AM
                    5 responses
                    15 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by adeelshahzad, Today, 03:54 AM
                    3 responses
                    19 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by bill2023, Yesterday, 08:51 AM
                    6 responses
                    27 views
                    0 likes
                    Last Post NinjaTrader_Erick  
                    Working...
                    X