Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Does the NinjaScript editor/compiler operrate before the preprocessor?

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

    Does the NinjaScript editor/compiler operrate before the preprocessor?

    I have excluded some properties from compilation with a #if but the Magic Code that gets generated still references them. Needless to say, the compiler chokes. Commenting out [NinjaScriptProperty] in the #if'd out code made things work.

    This sounds like a bug to me -- Magic Code generation is reacting to [NinjaScriptProperty] that the compiler will never see. Magic Code generation has no business reacting to code inside #iif ... #endif

    #2
    Hello ETFVoyageur,

    Pre-processor directives are not supported and will cause issues with NinjaScript.
    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,


    I'm showing your vote has already been added to feature request SFT-602, 'Allow NS auto-generated code to respond to pre-processor directives in an NS script'.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the information. I note that this issue goes back to at least 2015. Where we may disagree is that I regard this as a bug report, not a feature request.

      I can, at least to some extent, understand treating feature requests as a popularity contest. This issue, however, I believe to be a glaring bug that has been reported for a very long time -- going on ten years. Bugs should not be treated as popularity issues. I don't know how difficult it would be to do it right but, in principle, the magic code needs to get set up and added after the preprocessor has run. Some could wonder why I don't just comment out the code -- that's because doing so is not practical in this case -- we are talking about a little over 1100 lines of code.

      As to unsupported -- we agree that there can be compile-time issues. After all, that is what this thread is about. Do you know of any reason there would be a problem as long as the code is altered enough to compile, as I did in this case?

      Comment


        #4
        Hello ETFVoyageur,

        Are you referring to the NinjaScript generated code at the bottom of an indicator as "magic code"?

        Remove all pre-compilers from the script as these are not supported. (#regions are ok)

        Does the issue still occur?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Are you referring to the NinjaScript generated code at the bottom of an indicator as "magic code"?
          Yes ... is there some other term I ought to be using?

          Remove all pre-compilers from the script as these are not supported. (#regions are ok)
          First, that's not practical -- I assume that you mean preprocessor directives by "pre-compilers". Removing the #if ... #endif that is causing the problem is not practical because, as I mentioned above, I'm temporarily disabling over 1100 lines of code. How do you suggest I do that without #if ... #endif? Note that I did add // before all of the [NinjaScriptProperty] lines in that part of the code and then it compiled without complaint since the magic code no longer wanted to reference them.

          Second, I'm running into a similar problem with another file that has no preprocessor directives. I made a copy of the NT MACD file and made a few additions that I like. I marked my lines with /**/ at the start of each line I added. The editor gives me quite a list of diagnostics. It compiles fine, though -- this is an editor problem, not a compilation issue.

          Does the issue still occur?

          The code compiles just fine without that #if ... #endif.

          =====

          As I see it, there are two issues -- immediate and long-term.

          Immediate -- no matter what either of us thinks of the long term, it is what it is for now and that is what we have to work with. I'm presuming that the magic code should be fine as long as the file compiles without error. I understand your general principles objection to that. I'd feel the same way if I were in your shoes. But do you know of any specific problem provided the compilation succeeds?

          Long-term -- I believe you think that supporting the use of preprocessor directives is a feature request. My impression is that it is unlikely to ever get fixed if it is treated as a feature request. I, on the other hand, believe it is a serious bug. The preprocessor has been part of the development environment since the early days of C, so all C, C++, and C# developers expect it. I understand that you can define your environment and product in whatever way you think best. I also understand that many developers would be very happy to hear that you support the preprocessor.

          Last edited by ETFVoyageur; 05-14-2024, 01:04 PM.

          Comment


            #6
            Hello ETFVoyageur,

            The #if is not supported. It will not work as expected and will have to be removed.

            This is not a bug as it is the expected behavior. Our developers have not implemented supporting these. This is not something that prevents developers from creating NinjaScripts with supported code. This is a feature you want to be able to use is your code.

            Use regular if branching commands in the logic to avoid parts of the logic.

            Not everyone you can do in C# is available in NinjaScript. For example inheritance, widely used through C# application design, is not supported with Indicators and Strategies in NinjaScript. Though it may work in other applications, it is not supported in NinjaScript. This is due to the design of the product. Not all C# will be possible in NinjaScript.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            558 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            324 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
            545 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            547 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X