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

Is it possible to hide an indicator from the list in the indicator window

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

    Is it possible to hide an indicator from the list in the indicator window

    Explanation:

    I wrote a base class Indicator class that I'm using to inherit all my other indicators from.
    So this baseclass is defined as:

    Code:
    namespace NinjaTrader.NinjaScript.Indicators.AssistedTrades
    {
    
    public class ATBaseIndicator: Indicator
    {
    ...
    }
    }
    And any other indicator is defined as:

    Code:
    namespace NinjaTrader.NinjaScript.Indicators.AssistedTrades
    {
    public class ATVolumeRSI : ATBaseIndicator
    {
    ...
    }
    Since the baseclass isn't intended to apply to a chart, I'd like to hide it from the indicator list.
    Is that possible?

    #2
    Hello wjadevries,

    If the class is indicator or inheriting from Indicator there will not be a way to hide this from the list.
    Further, NinjaTrader does not support inheritance for Indicators, Strategies or other non-Addon script types. This may be cause undesired and unexpected behavior.

    This thread will remain open for any community members who would like to assist with this unsupported code.

    It may be a better idea to use a partial class.
    Attached is an example.
    PartialClassExamples_NT8.zip
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I'm using this inheritance method now for as long as I have Ninjatrader (about 6 months or so) without any problems.
      It has so much advantages, that I don't understand your comment.

      PS:
      The first partial class as per your example doesn't have any benefits if used for one specific indicator.
      You can't make a common library with it that way.
      And the second partial class in your example extends NinjaTrader's own Indicator class, which is rather dangerous.
      As the example says: make sure to use real long method names so they won't interfere with other extension developers.
      Clearly a warning which shows you shouldn't do it at all.

      Inheritance is the best way to make a base class for multiple indicators, that also doesn't have the above partial class disadvantages.
      So I keep going for inheritance (and don't understand why you say Ninjatrader doesn't support it because it might cause unexpected and undesired behavior.
      I think that's far more the case in the second example from you partial class, where you extend the common 'Indicator' base class!

      If I'm missing something here, please explain.
      Last edited by wjadevries; 02-17-2021, 12:19 PM.

      Comment


        #4
        Hello wjadevries,

        Any custom c# code that is not supported by our staff you can use at your own discretion. Our disclaimer is this may (or may not) cause unexpected behavior.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          ChelseaB, please see an important question at the bottom.

          Originally posted by wjadevries View Post
          I'm using this inheritance method now for as long as I have Ninjatrader (about 6 months or so) without any problems.
          It has so much advantages, that I don't understand your comment.

          PS:
          The first partial class as per your example doesn't have any benefits if used for one specific indicator.
          You can't make a common library with it that way.
          And the second partial class in your example extends NinjaTrader's own Indicator class, which is rather dangerous.
          As the example says: make sure to use real long method names so they won't interfere with other extension developers.
          Clearly a warning which shows you shouldn't do it at all.

          Inheritance is the best way to make a base class for multiple indicators, that also doesn't have the above partial class disadvantages.
          So I keep going for inheritance (and don't understand why you say Ninjatrader doesn't support it because it might cause unexpected and undesired behavior.
          I think that's far more the case in the second example from you partial class, where you extend the common 'Indicator' base class!

          If I'm missing something here, please explain.
          Dear wjadevries,

          I totally agree with you. Inheritance is a basic C# and any modern language capability that makes the code so much readable, and easier to write. I also use it in my indictors and have experience with 6 layers of indicator inheritance that works very smooth. Along the way I had some challenges, which the first suspicious was the inheritance, but non of them was. Some of them were related to the properties (show/hide per value change), and some were just mastering what is the correct way to define the each type of properties. Now that I have organized it, everything works smooth.

          Since I am using my own name space, I found it critical to have the full namespace for the inherited source, otherwise, NT doesn't generate the automatic code. Example:

          Code:
          namespace NinjaTrader.NinjaScript.Indicators.MyNameSpace
          
          {
          public class MyIndicator : NinjaTrader.NinjaScript.Indicators.MyNameSpace.MyBaseIndicator
          {
          ...
          I also agree with your observation regarding the use of partial class, which is actually use to spread class along multiple source files, basically for a team development, to allow multiple people to work on the same class at the same time. I use it on my base class to add different functionality (services) that reside in different files.

          Technically I could convert all my 6 layers to one class using partial class, but then you loss the the advantage of developing multiple indicators base on the similar code using inheritance, instead of physically duplicate the code.

          One drawback, is the missing ability to hide some of the "base indicators" which has functionality, but no actual display or usage from the indicator list. The only solution I found is to set the name as "", and so they still show in the list, but with no name. I wish there was a hide param for them.
          Last edited by Shai Samuel; 07-28-2022, 09:47 AM.

          Comment


            #6
            Hello Shai Samuel,

            I may be overlooking this, but what was the question at the bottom of your post?

            I see you have comment about how you wish there was a hide parameter for indicators to prevent these from showing in the indicator list. Are meaning for this to be asking for a feature request for inheritance to be supported?

            To address the comments on using inheritance would nice, I do agree that would be nice. Unfortunately, the limitation is that NinjaTrader needs to provide wrappers and do matching on specific classes to generate the UI. You can see some, but not all of this, in the autogenerated code that appears when compiling an indicator in the NinjaScript Editor.
            Inheritance breaks this and prevents NinjaTrader from being able to match the classes and properties used for populating the UI.
            In another vein (similar but not specifically related), static properties in strategies will break optimizations.
            These advanced C# concepts are nice to have, but are not necessary for creating a working indicator or strategy, or other templated NinjaScript type. Basically, NinjaTrader designed these classes to work with our UI, data delivery, and order delivery system and need to follow a specific format.

            Feel free to use inheritance with your own custom addons though, that are not indicators or strategies.

            If the point is to re-use code, then do this with partial classes. The code that would normally be duplicated would be the partial class and would not be duplicated.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea, thank you so much for your kind and detailed reply. Please see my question at the bottom in bold text.

              Yes, my question/wish was if there is any way to hide an indicator from the list.

              As far as your reply regarding the Inheritance, I appreciate the discussion,, and it's very important, since I would like to write clean and safe code. so here are several more points of my observation:
              • NinjaTrade actually does use inheritance with Indicators. Each of the base indicators the wizard produces, is inherit from Indicator.
              • The NT autogenerated script also uses both partial and inheritance, in a very smart way, by adding any indicator inherit from Indicator, to indicator itself.
              • Looking at the wrappers code (which is a beautiful functionality), they are created with taking the entire indicator class parameters into account, including the Inherited classes. I actually see the use they are doing with partial class, and it is smart.

              Thank you for your comment about the use of static variable. I will convert all the static of non static, that is easy and doesn't really cost anything.

              As far as my comments about partial, I take some of it back and extended it, once reading the MS documentation. Here is the relevant MS docs:
              There are several situations when splitting a class definition is desirable:
              • When working on large projects, spreading a class over separate files enables multiple programmers to work on it at the same time.
              • When working with automatically generated source, code can be added to the class without having to recreate the source file. Visual Studio uses this approach when it creates Windows Forms, Web service wrapper code, and so on. You can create code that uses these classes without having to modify the file created by Visual Studio.
              • When using source generators to generate additional functionality in a class.
              NinjaTrader smart engineers are using it very smartly to generate the wrappers.

              As far as the partial class as an alternative to Inheritance suggestion, I am confused, and would like to describe my understanding:
              • Let's assume I would like to create 2 different indicators based on the same base indicator: MyIndicatorA, and MyIndicatorB both using functionality of MyIndicatorBase.
              • Using inheritance, that would be "public class MyIndicatorA: MyIndicatorBase", and "public class MyIndicatorA: MyIndicatorBase".
              • What would be the alternative to do so using partial, using a single code for MyIndicatorBase?
              Last edited by Shai Samuel; 07-29-2022, 04:25 AM.

              Comment


                #8
                Hello Shai Samuel,

                You are correct, internally NinjaTrader is using inheritance for indicators and strategy classes. That doesn't change that you if further extend these it will break the matching done for the wrappers.

                Whatever the indicator is doing, that would be put in a partial class method. That method would be called from any indicator that needs the same code run. Need a button added? Need a plot set? Need something calculated? All done in the partial class.. The indicator instance is used in the partial class and does anything to the indicator you want.

                This would not be a base you inherit another indicator from. This would be shared partial classes.

                Below is a link to an example.
                https://ninjatrader.com/support/foru...ow#post1142340
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Similar thread with additional insights is here.

                  Comment


                    #10
                    I have successfully
                    • Hidden indicators from the list
                    • Created base classes for indicators to derive from.
                    ​See this post here https://forum.ninjatrader.com/forum/...27#post1243127

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Rapine Heihei, Today, 08:19 PM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by Rapine Heihei, Today, 08:25 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post Rapine Heihei  
                    Started by f.saeidi, Today, 08:01 PM
                    1 response
                    9 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by Rapine Heihei, Today, 07:51 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post Rapine Heihei  
                    Started by frslvr, 04-11-2024, 07:26 AM
                    5 responses
                    98 views
                    1 like
                    Last Post caryc123  
                    Working...
                    X