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

Abstract base class for indicator -> compile error

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

    Abstract base class for indicator -> compile error

    Hi,

    I have an abstract base class for some indicators.
    public abstract class MTF_core : Indicator, ICustomTypeDescriptor

    The problem is that for this abstract indicator the editor also generates automatic code

    #region NinjaScript generated code. Neither change nor remove. ....

    After generation of code there is compile error, becuase it is not possible to generate abstract object.

    MTF_core.cs Es konnte keine Instanz der abstrakten Klasse oder Schnittstelle 'NinjaTrader.NinjaScript.Indicators.MTF_core' erstellt werden. CS0144

    Please exclude abstract indicators for code generation

    Thanks
    Klaus

    #2
    Hello Klaus,

    I have submitted a feature request to our development on your behalf to exclude the generation of NinjaTrader Generated code, when implementing an indicator as an abstract class or when an indicator inherits from an abstract class.

    That said, using an abstract class is not supported by NinjaTrader Support to do. My suggestion would be to move the code to a new namespace and call the methods of the class from the indicator, instead of attempting to inherit the entire indicator from an abstract class.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      using an abstract class is not supported by NinjaTrader
      In NT7, you can tell the compiler to skip adding generated code by
      removing the Description attribute for the class.

      Perhaps the same trick works in NT8?

      For example,

      bltBaseIndicator.cs:
      Code:
      namespace NinjaTrader.Indicator
      {
           /* !!! NO DESCRIPTION -- skip automatic code generation !!! */
          abstract public class bltBaseIndicator : Indicator, ICustomTypeDescriptor
          {
          ...
          }
      }
      bltFibonacci.cs:
      Code:
      namespace NinjaTrader.Indicator
      {
          [Description("This attribute generates NinjaTrader code regions")]
          public class bltFibonacci : bltBaseIndicator
          {
          ...
          }
      }

      Comment


        #4
        Hello,

        A workaround is to add the script to the Addons folder instead of the Indicator or Strategy folder. Any scripts in the Addon folder are still compiled but no NinjaScript code is auto generated.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi guys,

          I have a similar, but opposite, issue.

          I have a base class, maBase, which inherits from your standard Indicator class. I then have another indicator, lets call it maEma, which inherits from maBase.

          When I compile maEma inheriting from maBase, none of the NinjaScript generated Code is created, whereas if I change maEma to inherit from Indicator, it is.

          Is there a reason why the auto generated code isn't created when I inherit from maBase, which in turn inherits from Indicator? Is there a way I can force it to auto generate the code, as it is technically an indicator at this second level of inheritance from Indicator.

          As always, Thanks!
          mrlogik
          NinjaTrader Ecosystem Vendor - Purelogik Trading

          Comment


            #6
            Hi mrlogik,

            Do you have a shell indicator exported that demonstrates?

            Are you compiling the indicator from the NinjaScript Editor?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea,

              I am compiling within the NT editor. I figured it out.

              It appears if you have //Indicator after the inherited class name, NT sees the word Indicator and auto generates the code.

              For example, my base class is

              Code:
              namespace NinjaTrader.NinjaScript.Indicators
              {
                  public class testBase : Indicator
                  {
                  }
              }
              The class inheriting is

              Code:
              namespace NinjaTrader.NinjaScript.Indicators
              {
                  public class testInherited : testBase 
                  {
                  }
              }
              If I keep the testInherited class as is, and compile, the auto code will not generate.

              However, if I add a //Indicator after testBase, it will. See below

              Code:
              namespace NinjaTrader.NinjaScript.Indicators
              {
                  public class testInherited : testBase  //Indicator
                  {
              
                  }
              }
              Hope this helps anyone else looking to use inheritance.

              Thanks again.
              Anthony
              mrlogik
              NinjaTrader Ecosystem Vendor - Purelogik Trading

              Comment


                #8
                As of 8.0.4 is it now the official NT intention that abstract base classes derived from Indicator should work and should not result in an indicator in the indicator list?
                Last edited by QuantKey_Bruce; 03-02-2017, 07:13 AM.
                Bruce DeVault
                QuantKey Trading Vendor Services
                NinjaTrader Ecosystem Vendor - QuantKey

                Comment


                  #9
                  Bruce,

                  An FYI, the base class (mine is not abstract) will show in the indicator list. I simply name it appropriately so a user knows it should be ignored.
                  mrlogik
                  NinjaTrader Ecosystem Vendor - Purelogik Trading

                  Comment


                    #10
                    Originally posted by mrlogik View Post
                    An FYI, the base class (mine is not abstract) will show in the indicator list. I simply name it appropriately so a user knows it should be ignored.
                    If you make it abstract, it should be omitted from the list, because it cannot be instantiated - at least if it is in the AddOns directory where NinjaScript is not added automatically. It used to be true that if it was in the Indicator directory it would still attempt to add the NinjaScript even if it is abstract (the issue of this thread) however that may have been since corrected.
                    Last edited by QuantKey_Bruce; 03-02-2017, 08:05 AM.
                    Bruce DeVault
                    QuantKey Trading Vendor Services
                    NinjaTrader Ecosystem Vendor - QuantKey

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by PaulMohn, Today, 12:36 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post PaulMohn  
                    Started by love2code2trade, 04-17-2024, 01:45 PM
                    4 responses
                    38 views
                    0 likes
                    Last Post love2code2trade  
                    Started by alifarahani, Today, 09:40 AM
                    2 responses
                    14 views
                    0 likes
                    Last Post alifarahani  
                    Started by junkone, Today, 11:37 AM
                    3 responses
                    21 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by frankthearm, Yesterday, 09:08 AM
                    12 responses
                    44 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Working...
                    X