Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Best practice for 'including' constants, enumerations etc.

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

    Best practice for 'including' constants, enumerations etc.

    Hi guys,

    Quick question;

    Given that C# doesn't have an #include directive, what is the best practise in NT for including my useful constants and enumerations etc. which are shared by my family of indicators, rather than having to duplicate them within each indicator?

    thanks

    #2
    Hello trader_rick,

    This type of sharing is a core fundamental of C# as a language, this is known as the concept of namespaces and object-oriented programming.

    C# does have the ability to include other files or assemblies, you would just need to either use the fully qualified name to that object or provide a using statement at the top of the script so you can use the objects in that namespace within this script.

    I would suggest for this question that you review some general C# namespace tutorials as that will clear this quesion up for you. NinjaTrader is simply compiling the C# code you write so the way C# works as a language in whole would apply toward NinjaScript.




    You can define a class in a custom namespace as one example. This could contain shared properties or enums, and then to access that class you would use its fully qualified name from any other script.

    You can also find examples of this concept being used throughout the platform, for example how every strategy can access the "NinjaTrader.Cbi.MarketPosition" enum, this enum is defined in a specific Namespace (NinjaTrader.Cbi) which can then be referenced in any strategy. By default, strategies have the "using NinjaTrader.Cbi" at the top which then makes it so later in that same script MarketPosition is now able to be found.


    I look forward to being of further assistance.

    Comment


      #3
      Thanks Jesse

      Comment


        #4
        Originally posted by trader_rick View Post
        Hi guys,

        Quick question;

        Given that C# doesn't have an #include directive, what is the best practise in NT for including my useful constants and enumerations etc. which are shared by my family of indicators, rather than having to duplicate them within each indicator?

        thanks
        Use new partial classes of Indicator and Strategy.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        571 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        331 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        549 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        550 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X