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

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​

    #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.

      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.

        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.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by SnailHorn, 05-02-2024, 10:49 PM
            3 responses
            27 views
            0 likes
            Last Post SnailHorn  
            Started by giulyko00, Today, 11:49 AM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by marksingh87, 02-13-2024, 04:55 PM
            6 responses
            210 views
            1 like
            Last Post mshrstv
            by mshrstv
             
            Started by SnailHorn, Today, 08:38 AM
            2 responses
            4 views
            0 likes
            Last Post SnailHorn  
            Started by Skifree, Yesterday, 11:38 PM
            1 response
            16 views
            1 like
            Last Post NinjaTrader_LuisH  
            Working...
            X