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

Extending functionality of existing NT8 indicator

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

    Extending functionality of existing NT8 indicator

    Hello,

    Do you have an example for best practices for extending the functionality of an "out of the box" NT8 indicator and do so such that the new custom indicator is NinjaScript available with added API?

    I'm looking to add shading to the Donchian Channel indicator but only under certain circumstances. And to provide a boolean when the shading is occurring.

    I see two ways to do this:

    1. Copy and paste the code from the existing Donchian Channel indicator code that's provided. Then add the necessary code.
    2. New class that inherits from the Donchian Channel class.

    I was able to successfully do #1 for adding to a chart only. However, when I added more logic so that additional attributes are available in a strategy, I'm getting an index error that doesn't make sense.

    Before I code any further, I was wondering if you have a such an example.

    Thanks!
    Matt

    #2
    Hello StealthM93,

    To extend a existing indicator its generally suggested to open that indicator then Right click -> Save as. That will rename the relevant classes/ Name = "" strings and gets the script duplicated quickly. The only time that won't work completely would be for items that use custom classes/enums/namespaces you may still need to manually rename some resources in the files after doing a save as.

    Inheriting from an indicator would not be suggested due to how the indicator system works and how the generated code in the files work. If you are making modifications to how the indicator works it would be best to duplicate the whole code and modify it as needed.

    The index error part would be difficult to say what happened, we would need more specific details on what you added or changed there.

    when I added more logic so that additional attributes are available in a strategy
    If you added public properties or changed items that were private to public to expose them it may be how you did the modification causing the error. I would suggest to post a sample of what you mean by this statement so we could better understand if exposing data was the cause of the error.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      Thank you for the feedback. Based on your comments, I have done the following which is working thus far.

      Added an empty constructor. Got an error that one didn't exist, so I added it.
      Code:
      [FONT=Courier New]public DonchianChannelRange() { }
      
      protected override void OnBarUpdate() {
      
         if (CurrentBar <= MinRangePeriod) return; // custom code to ensure enough bars
      
         // **** vvv NT8 code vvv ****
         double max0 = max[0];
         double min0 = min[0];
      
         Value[0] = (max0 + min0) / 2;
         Upper[0] = max0;
         Lower[0] = min0;
         // **** ^^^ NT8 code ^^^ ****
      
         // Added my custom logic here
      }[/FONT]
      Then I have a basic C# Property code with a get only. This is available and working for the strategy.

      I added a custom constructor to only have the needed parameters. However, when using that in a strategy, it resulted in that Bars ago I mentioned previously. In looking at the strategy code, I discovered that NT8 creates a new constructor behinds scenes with parameters using all the custom NinjaScript properties that I added. Using that generated constructor works.

      Thanks again!
      Matt

      Comment


        #4
        Hello StealthM93,

        Right, custom inheritance on indicators is not something we suggest to use due to how the platform generates constructors for the various parameter sets that indicators have by default. Those constructors need to be used due to how indicators are instantiated and cached.

        If you are proficient at C# you can use any of the mechanics of C# however you may need to debug situations which are not commonly used in the platform like one indicator inheriting from another. If you run into other use issues I could really only suggest to remove that inheritance and just do a SaveAs on the original indicator to avoid having to do extra work.




        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi Jesse,

          Just a quick follow up and conclusion. Doing the copy & paste, which is what I have done, is essentially the same as Save As.... Although, doing the Save As... approach is safer. Anyway... that is what I did along with the updates mentioned above.

          Now, I just need to make sure the indicator OnBarUpdate is called before the strategy OnBarUpdate, which you have kindly answered.

          Thanks!
          Matt

          Comment


            #6
            If someone has updated an indicator for the Adaptive Donchian Channel with shading, could some kind soul attach it here
            or point me towards a link that has it?

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by AaronKoRn, Yesterday, 09:49 PM
            0 responses
            11 views
            0 likes
            Last Post AaronKoRn  
            Started by carnitron, Yesterday, 08:42 PM
            0 responses
            10 views
            0 likes
            Last Post carnitron  
            Started by strategist007, Yesterday, 07:51 PM
            0 responses
            12 views
            0 likes
            Last Post strategist007  
            Started by StockTrader88, 03-06-2021, 08:58 AM
            44 responses
            3,982 views
            3 likes
            Last Post jhudas88  
            Started by rbeckmann05, Yesterday, 06:48 PM
            0 responses
            10 views
            0 likes
            Last Post rbeckmann05  
            Working...
            X