• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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.

    https://docs.microsoft.com/en-us/dot...de/namespaces/
    https://docs.microsoft.com/en-us/dot...ing-namespaces

    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.
    JesseNinjaTrader Customer Service

    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 ajsdnyyrr1234DDf, Today, 09:39 AM
        0 responses
        5 views
        0 likes
        Last Post ajsdnyyrr1234DDf  
        Started by afoschini, Today, 09:18 AM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Jim  
        Started by rexsole, Today, 08:02 AM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Started by johnnybegoode, Yesterday, 07:06 PM
        1 response
        18 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by johnnybegoode, Yesterday, 10:06 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X