Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Common DataSeries and BoolSeries etc. for NT 8 indicators

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

    Common DataSeries and BoolSeries etc. for NT 8 indicators

    Hi,

    There are a number of data series etc. that I use repeatedly in different indicators - for example, the number of consecutive of bars up or down - that require events such as OnBarUpdate and tests for first tick of bar, etc. I'm aware that you can create add ons that include partial indicator classes, etc. What I'm wondering is, what's the best approach in NT8 for creating a common library of methods and properties, where many of the properties will be series of various types that involved a bit of work to calculate? My first thought was just to create a new indicator that extends Indicator, put all the logic there, and then just have new indicators extend the "common" one. But is that the best approach? If you have a model, that would be great. I'm aware of the example "MySharedMethodsAddonExample.zip" - the difference is I would want to leverage all of the standard events in order to calculate the shared information.

    Thanks,

    Gordon
    Last edited by grose; 12-19-2019, 06:22 PM.

    #2
    Originally posted by grose View Post
    My first thought was just to create a new indicator that extends Indicator, put all the logic there, and then just have new indicators extend the "common" one. But is that the best approach?
    Yes, that is the best approach.

    Comment


      #3
      Hello grose,

      Thank you for the post.

      We don't generally suggest creating a base class and then inheriting from it but you can certainly do that if you want because we are using C#.

      We normally won't suggest this type of design because this can cause problems down the line if you plan to export the code and can also be difficult to debug. We don't provide any samples that align with that development style to learn from so we generally don't provide support in that area. If you are already well versed in C# and feel confident that you can debug what you create you could certainly use all of the features of C# like inheritance.

      The most suggested route is to use an indicator to contain the logic and just call that indicator from where you needed it, this system already exists and is used in most other scripts. For example adding a custom public property or method could be accessed by calling the indicator:
      double value = MyCustomIndicator(PassedInDataOrValues).MyCustomMe thod(OtherPassedInData);

      This allows for the normal overrides and indicator properties to be used, you could also do more advanced items like pass data in or other parameters. You can see this used with indicators like the ZigZag in how it calculates and uses a method to do custom reporting.

      When creating common shared functions which may require NinjaScript properties or calculation from the current script the other general suggestion is to use a partial class of that type like a partial class Indicator. This is documented in the code breaking changes guide because NT7 previously came with a partial class example (UserDefinedMethods.cs) that was removed from NT8: https://ninjatrader.com/support/help...hangesOverview

      The NT8 example does not show the same concept that was in NT7, it does not make a partial Indicator class and instead passes data to the method. You could just do: partial class Indicator { (like shown in NT7) and would have access to the NinjaScript variables when called from your script.




      I look forward to being of further assistance.




      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      646 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      367 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      570 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X