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

Object oriented programming in NT

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

    Object oriented programming in NT

    Hi,

    I have some indicators that I am developing which do use the very same computational engine. Instead of copy-pasting the code of the computational engine in each indicator I wanted to create a class which embeds it and include it within each indicator (as I would do in c++). As I am new to developing for NT8 and c# I wanted to ask you if I can do that and, if yes, how can I do that.

    Thank you in advance for your help!
    Best regards.

    #2
    This is a very common question.

    I'd recommend you look hard at using an abstract base class.

    Although not supported by NT Support, IMHO, this concept
    works well for many many uses cases. You'll have to press
    NT Support if you want details of why they only recommend
    using partial classes -- apparently, there are some rare use
    case(s) on the edge somewhere (strategy optimization?) that
    trigger some vague problems, though I've never seen their
    examples and I've never experienced these issues. YMMV.

    Good reading here, here, and here.

    -=o=-

    In addition, you'll want to organize a private namespace for
    yourself, for enums, extensions, and other classes. I use
    a file named 'BltCommon.cs' file to hold these, and add
    this code,

    using Blt.Common;

    to all my NinjaScript objects.

    Read more about a sample 'MyCommon.cs' here.

    Good luck!

    Last edited by bltdavid; 09-19-2023, 05:31 AM.

    Comment


      #3
      Hello VFI26,

      From a support standpoint we suggest making a normal C# custom class if you wanted to split code that can be shared between scripts. There is currently no support for custom inheritance on NinjaScript classes and that can cause issues depending on the use case. We would not suggest using an abstract base class. Our support cannot assist with any type of custom inheritance structures so in case there is a problem you would be on your own. If you are using a C# class instead that we can assist with if you needed help.

      NinjaScript is C# programming language so you can use a standard C# class structure to make custom methods and pass data or properties from a script to that class if needed.

      As a very simple example you can view the TrendLines indicator which uses a class called TrendRay. That indicator has a few private classes used. To make a class available to other scripts you can instead create a public class inside a file within the addons folder and then reference that class from any scripts that may need to use it.


      JesseNinjaTrader Customer Service

      Comment


        #4
        Thank you Jesse and bltdavid!

        Thanks to your suggestions I was able to organize myimplementation in the way I wanted.

        Best regards.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by itrader46, Today, 10:22 AM
        0 responses
        12 views
        0 likes
        Last Post itrader46  
        Started by NM_eFe, Today, 10:13 AM
        0 responses
        3 views
        0 likes
        Last Post NM_eFe
        by NM_eFe
         
        Started by hdge4u, Yesterday, 12:23 PM
        1 response
        10 views
        0 likes
        Last Post hdge4u
        by hdge4u
         
        Started by 1001111, Today, 09:45 AM
        0 responses
        11 views
        0 likes
        Last Post 1001111
        by 1001111
         
        Started by DTSSTS, 01-28-2024, 12:07 PM
        11 responses
        559 views
        0 likes
        Last Post bmo111
        by bmo111
         
        Working...
        X