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

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.
    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 nandhumca, Today, 03:41 PM
        0 responses
        4 views
        0 likes
        Last Post nandhumca  
        Started by The_Sec, Today, 03:37 PM
        0 responses
        3 views
        0 likes
        Last Post The_Sec
        by The_Sec
         
        Started by GwFutures1988, Today, 02:48 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by ScottWalsh, 04-16-2024, 04:29 PM
        6 responses
        33 views
        0 likes
        Last Post ScottWalsh  
        Started by frankthearm, Today, 09:08 AM
        10 responses
        36 views
        0 likes
        Last Post frankthearm  
        Working...
        X