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

Exclude indicator from indicators dialog

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

    Exclude indicator from indicators dialog

    Hi NinjaTrader team,

    is there a way to exclude an indicator from the indicators dialog? Like I can exclude an indicator property from the property sheet using Browsable(false)?

    I'd like to host some indicators inside strategies or other indicators, so I can use indicator instances as building blocks to reuse some code for recurring tasks, but I don't want the indicators to be available as standalone indicators in the indicators dialog.

    Thanks,
    Heiko


    #2
    Hi Heiko, thanks for posting. You can make a partial class to create shared code that will not show up in the indicators list. See the example here:
    I have class called Logger... I want to use this class inside indicator or strategy (ninjatrader objects). This Logger class should write text using Time[0],


    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by schwarzerh View Post
      ... as building blocks to reuse some code for recurring tasks, but I don't want the indicators to be available as standalone indicators in the indicators dialog.
      Try using an abstract base class.

      Good reading here.

      Comment


        #4
        Hi Chris, hi bltdavid,

        thanks for your help - I think bltdavid understood what I was trying to express. And, obviously this discussion has already been going on for a while :-)

        Here are my two cents. Consider this code snippet

        Code:
        using NinjaTrader.Custom.AddOns.Schwarzer.Framework.Condition;
        using NinjaTrader.Custom.AddOns.Schwarzer.Framework.Visualization;
        
        namespace NinjaTrader.NinjaScript.Indicators.Schwarzer.Experimental
        {
            /**
            * <author>Heiko Schwarzer</author>
            */
            public abstract class ConditionVisualizer : Indicator
            {
                private ICondition _condition;
                private IViewElement _viewElement;
        
        
                protected override void OnStateChange()
                {
                    if (State == State.DataLoaded)
                    {
                        _condition = CreateCondition();
                    }
                }
        
        
                protected abstract ICondition CreateCondition();
        
        
        
                protected override void OnBarUpdate()
                {
                    if (_condition.IsTrue())
                    {
                        if (_viewElement == null)
                        {
                            _viewElement = CreateViewElement();
                            _viewElement.Paint();
                        }
        
                        return;
                    }
        
                    if (_condition.IsFalse() && _viewElement != null)
                    {
                        _viewElement.Remove();
                        _viewElement = null;
                    }
                }
        
        
                protected abstract IViewElement CreateViewElement();
            }
        }​

        Now I have an abstract indicator base class which I can derive from. Simply implement CreateCondition() and CreateViewElement(), and you can have, for instance, an indicator that plots a little triangle at the low or high of each reversal bar, In reality, this base class would be more complex, of course, I am trying to keep it simple for discussion purposes. You have to use a little imagination ...

        Now, here comes the point:

        I'd like the implementations of ICondition (and maybe also IViewElement) in this example to be instances of Indicator. So they can have their own data feed. So they can use their plot capabilities. So they can trigger an alert. etc. etc.

        Think something like

        Code:
        using NinjaTrader.Custom.AddOns.Schwarzer.Framework.Condition;
        
        namespace NinjaTrader.NinjaScript.Indicators.Schwarzer.Experimental
        {
            /**
            * <author>Heiko Schwarzer</author>
            */
            public class ReversalBarCondition : Indicator, ICondition
            {
                public bool IsTrue()
                {
                    return (Value[0] > 0);
                }
        
                public bool IsFalse()
                {
                    return !IsTrue();
                }
        
                protected override void OnBarUpdate()
                {
                    if (CurrentBar == 0)
                    {
                        return;
                    }
        
                    if (High[0] > High[1] && Close[0] < Close[1])
                    {
                        Value[0] = 1;
                    }
                }
            }
        }
        ​

        This way we could construct an entire component framework where you can easily reuse framework classes like ConditionVisualizer and also ICondition implementations like ReversalBarCondition in different contexts. Because of the infrastructure it provides, Indicator would serve as a perfect base class to construct reusable components from.

        The only problem is:

        ReversalBarCondition from the above example would need to be a concrete Indicator implementation which would be listed in the indicators dialog.

        Which you would not want. Because it is only a component to be hosted inside another indicator or a strategy.

        So how about a Browsable(false) annotation applicable to the indicator class?

        Hope this helps the discussion. Any feature request in that direction would have my support. I would even implement it if NinjaTrader accepts me as a freelance contractor :-)

        Regards,
        Heiko
        Last edited by schwarzerh; 11-25-2022, 02:54 AM.

        Comment


          #5
          Hey, you did it !

          Thank you very much, NinjaTrader Team !

          :-)

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by arvidvanstaey, Today, 02:19 PM
          0 responses
          2 views
          0 likes
          Last Post arvidvanstaey  
          Started by mmckinnm, Today, 01:34 PM
          3 responses
          5 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by f.saeidi, Today, 01:32 PM
          2 responses
          5 views
          0 likes
          Last Post f.saeidi  
          Started by alifarahani, 04-19-2024, 09:40 AM
          9 responses
          55 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Conceptzx, 10-11-2022, 06:38 AM
          3 responses
          60 views
          0 likes
          Last Post NinjaTrader_SeanH  
          Working...
          X