Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding a NinjaScriptProperty to a derived class

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

    Adding a NinjaScriptProperty to a derived class

    Hello.

    I have created a custom indicator derived from Bollinger, and would like to add a couple of properties to it.

    I have also tried adding more series similar to Lower/Middle/Upper, but again, no luck.

    The reason I've added the Bollinger's properties here as well is because I've tried a couple of things, but I'm missing a piece of understanding, so i just left the latest code.

    what am i doing wrong, is there something fundamental I'm missing? please help!
    An example would be a huge help if there is one.

    Thanks, Aviram Y.


    Code:
    [HASHTAG="t3322"]region[/HASHTAG] Properties
    [Browsable(false)]
    [XmlIgnore()]
    public Series<double> BandsWidth
    {
    get { return Values[5]; }
    }
    
    [Browsable(false)]
    [XmlIgnore()]
    public Series<double> UpperDev
    {
    get { return Values[4]; }
    }
    
    [Browsable(false)]
    [XmlIgnore()]
    public Series<double> LowerDev
    {
    get { return Values[3]; }
    }
    
    [Browsable(false)]
    [XmlIgnore()]
    public Series<double> Lower
    {
    get { return Values[2]; }
    }
    
    [Browsable(false)]
    [XmlIgnore()]
    public Series<double> Middle
    {
    get { return Values[1]; }
    }
    
    [Browsable(false)]
    [XmlIgnore()]
    public Series<double> Upper
    {
    get { return Values[0]; }
    }
    
    [Range(0, int.MaxValue), NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "NumStdDev", GroupName = "NinjaScriptParameters", Order = 0)]
    public double NumStdDev
    { get; set; }
    
    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 1)]
    public int Period
    { get; set; }
    
    [NinjaScriptProperty]
    [Display(Name="Direction", GroupName = "NinjaScriptParameters", Order = 2)]
    public string StrategyDirection
    { get; set; }
    #endregion​
    Aviram Y
    NinjaTrader Ecosystem Vendor - Aviram Y

    #2
    Did you also add plots 3, 4 and 5 in State.SetDefaults?
    eDanny
    NinjaTrader Ecosystem Vendor - Integrity Traders

    Comment


      #3
      I did, but I actually just solved my problem, i was so confused on why it doesn't work, the reason is because i copied the syntax from the class declaration of Bollinger directly.

      because bollinger is declared like so
      Code:
      public class Bollinger : Indicator
      I didn't realize that i need the full path of the Bollinger indicator when declaring my class so i declared it this way
      Code:
      public class AdaptiveBollinger : Bollinger
      When i should've just input the full path to the indicator:
      Code:
      public class AdaptiveBollinger : NinjaTrader.NinjaScript.Indicators.Bollinger
      Is there a reasoning for this? everything works fine now, but i am still a bit confused on why the Bollinger class uses Indicator as a base without any path, I'm still missing some fundamentals on classes, since i come from a game design background i do have experience but all self taught and very specific.

      Aviram Y
      NinjaTrader Ecosystem Vendor - Aviram Y

      Comment


        #4
        Another question, when i use the AdaptiveBollinger in my strategy like so
        Code:
        private AdaptiveBollinger adaptiveBollinger;
        
        adaptiveBollinger = AdaptiveBollinger(2, 20, "long");
        AddChartIndicator(adaptiveBollinger);​
        i use the base.OnStateChange of the Bollinger inside the OnStateChange scope of AdaptiveBollinger before if (State == State.SetDefaults) , and i do the same for the OnBarUpdate before calculating any custom logic.
        Code:
                protected override void OnStateChange()
                {
                    base.OnStateChange();
                    if (State == State.SetDefaults)
                    {
                        Description                    = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionBollinger;
                        Name                        = "AdaptiveBollinger";
                        IsOverlay                    = true;
                        IsSuspendedWhileInactive    = true;
                        NumStdDev                    = 2;
                        Period                             = 20;​
                    }
                }
        but the AdaptiveBollinger is drawing the default Bollinger values on the chart (Bollinger(2,14)) and ignores the arguments i pass onto Adaptive Bollinger unless i set the NumStdDev and Period in State.Configure

        Code:
                    else if( State == State.Configure)
                    {
                        base.NumStdDev = NumStdDev;
                        base.Period    = Period;
                    }​
        is this the right approach? am i doing something wrong?

        What exactly am i supposed to do with the NumStdDev and Period? or for the sake of a better understanding, any argument that belongs to the base class when called like i mentioned above.
        Last edited by Aviram Y; 03-15-2023, 12:14 PM.
        Aviram Y
        NinjaTrader Ecosystem Vendor - Aviram Y

        Comment


          #5
          Hello Aviram Y,

          NinjaTrader does not support inheritance with indicators or strategies.

          Unfortunately, the wrappers that create overload signatures and optimization instances cannot recognize inheritance.

          This means you would need to just copy the logic from one script into another.

          If you want to share methods, you can use a partial class.
          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: namespace NinjaTrader.NinjaScript.Indicators.AssistedTrades { public class ATBaseIndicator: Indicator { ... } } And any other indicator is defined as: namespace NinjaTrader.NinjaScr
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thanks for the clarification! very much appreciated.
            Aviram Y
            NinjaTrader Ecosystem Vendor - Aviram Y

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            633 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            364 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            567 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            568 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X