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

Any news on precompiler directives?

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

    Any news on precompiler directives?

    I usually define directives like this, at the begining of the code :

    define __AAA__
    #ifndef __AAA__
    define __BBB__
    #endif


    then in the code I use a lot of instances of :
    #ifdef __AAA__
    some code for AAA
    #else//__BBB__
    some slight change of code for BBB
    #endif


    But when I do that in Ninja, the compiler throws a lot of errors. Here
    Hello, Could the use of preprocessor directives cause an issue with NT8? I saw on an old post that it was not supported, but I see it compiles and runs without problem. Regards,

    it is said it is not supported, but a request was made. So what is the latest news on precompiler directives.
    ​​

    #2
    Have you tried them?
    What errors are you getting?

    They work fine. I use them regularly in my code.

    It's pretty heavy-handed for NT to imply they won't work.

    They work fine, just use them for code, not for properties.

    That is, stay away from using preprocessor directives to
    enable/disable compiler visibility for public properties.

    -=o=-

    The compiler generates NinjaScript magic code at the bottom
    of each Indicator (but not Strategies or AddOns). This involves
    quite of bit of searching for properties, which are usually all
    grouped together in a single region in your code. But this is
    just a suggested code organization technique, it's not required.
    You could sprinkle your public properties into your code any way
    you want -- the NT compiler would still find them and use them
    in the auto-generated magic code. It helps that NT8 added the
    new NinjaScriptProperty decoration for public properties, since
    it is only these properties that need to be included in the auto
    generated code. But, I digress.

    My point is: the NT compiler's 'magic code generator' doesn't
    understand the 'visibility factor' of code you turned 'off' using
    a preprocessor directive. That is, despite what the compiler's
    code emitter produces, the magic code property scanner sees
    all properties -- because that code ignores the directives.
    But, again, I digress.

    -=o=-

    Remember, when NT says 'unsupported', that does not really
    say anything about whether it works or not -- it ONLY means
    whether NT support folks will help you on that topic.

    The point is: whether something 'will work' or not is always a
    different question from whether something is 'supported' or not.

    Their job is to support NinjaTrader product(s) and the NinjaScript
    framework.

    They don't 'support' ML.net, or nuget, or preprocessor directives,
    or a myriad of other things because they didn't write that stuff.

    The words 'supported' and 'unsupported' always need a bit of
    context when used by NT support.

    Just my 2˘.


    Comment


      #3
      Originally posted by bltdavid View Post
      My point is: the NT compiler's 'magic code generator' doesn't
      understand the 'visibility factor' of code you turned 'off' using
      a preprocessor directive. That is, despite what the compiler's
      code emitter produces, the magic code property scanner sees
      all properties -- because that code ignores the directives.
      It would be nice if the automatic code generator that puts the helper code at the bottom of indicators for instance caching, etc. were enhanced to support preprocessor directives like #ifdef, etc. Most likely, the reason it does not is simply that NinjaTrader did not anticipate that very many of its users would use this technique and yet it was judged to be not a trivial thing to add. (That having been said, if they can add it, it would be a plus.)

      I definitely agree that just because something isn't "supported" doesn't mean it's impossible - what it means is it's beyond what they've agreed to help with or document and/or beyond what they warrant should continue to work in most future versions. It doesn't mean any more or any less.
      Last edited by QuantKey_Bruce; 03-18-2023, 06:01 AM.
      Bruce DeVault
      QuantKey Trading Vendor Services
      NinjaTrader Ecosystem Vendor - QuantKey

      Comment


        #4
        Hello alanlopen,

        While you technically can use that feature of C# that is not something which NinjaScript supports at all so you may run into errors depending on the use case. In general we suggest avoiding using pre compiler directives because of that.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by bltdavid View Post
          Have you tried them?
          What errors are you getting?

          They work fine. I use them regularly in my code.

          It's pretty heavy-handed for NT to imply they won't work.

          They work fine, just use them for code, not for properties.

          That is, stay away from using preprocessor directives to
          enable/disable compiler visibility for public properties.
          just by putting

          define __AAA__
          #ifndef __AAA__
          define __BBB__
          #endif​

          at the top of the code gives error CS1024 CS1025 CS1028 lol. Apprently #ifndef is not defined

          Comment


            #6
            It's a pity the properties are not compatible with directives but I manage to do what so far

            Comment


              #7
              alanlopen The #ifndef pre-processor directive is part of C and C++ but not C#. To do the equivalent in C#, simply use "#if !whatever" to test if "whatever" has not been defined. You can find more information in the relevant Microsoft documentation.

              Thanks.
              Multi-Dimensional Managed Trading
              jeronymite
              NinjaTrader Ecosystem Vendor - Mizpah Software

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by jaybedreamin, Today, 05:56 PM
              0 responses
              3 views
              0 likes
              Last Post jaybedreamin  
              Started by DJ888, 04-16-2024, 06:09 PM
              6 responses
              18 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Jon17, Today, 04:33 PM
              0 responses
              1 view
              0 likes
              Last Post Jon17
              by Jon17
               
              Started by Javierw.ok, Today, 04:12 PM
              0 responses
              6 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Working...
              X