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.

    Learn how to organize C# code with namespaces, file-scoped namespace declarations, global usings, static usings, and type aliases.

    Learn how to organize C# code with namespaces, file-scoped namespace declarations, global usings, static usings, and type aliases.


    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 Hwop38, 05-04-2026, 07:02 PM
        0 responses
        154 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by CaptainJack, 04-24-2026, 11:07 PM
        0 responses
        306 views
        0 likes
        Last Post CaptainJack  
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        244 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        345 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        176 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Working...
        X