Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NinjaScript generated code

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

    NinjaScript generated code

    I'm using a unique namespace to build an indicator using many files for classes.
    This is the first time I've used this approach and is because my indicator is getting too big.
    I have only 1 file that is the main indicator file with "public class Big_Indi : Indicator" and all other files are classes in the namespace but not inheriting Indicator.

    I can compile all files and get clean compiles and the indicator works as expected, however, whenever there is a coding error then the "NinjaScript generated code" get generated at the bottom of the file. If I fix my error and then recompile before I delete the "NinjaScript generated code" at the bottom of the file then I get a compile error because Ninjatrader creates another copy of the "NinjaScript generated code" -- so i have 2 identical copies of the Nijatrader generated code and the compiler complains about it of course.

    So, why are you generating 2 copies of this code at the bottom of my class file that's inheriting from Indicator?
    I haven't ever seen this happen before and I've written dozens of indicators, however this is the first time that I've split my indicator into multiple files so I suspect that's the problem.
    Is there a way to get Ninjatrader to behave more nicely with my multi-file approach?
    Is there a Ninjatrader preferred multifile indicator setup?
    Do you have any suggestions on how I can inhibit this double copy of your generated code at the bottom of my indicator?.
    The "NinjaScript generated code" only happens in the class that is inheriting Indicator.

    #2
    Hello dtl-saw,

    Thanks for your post.

    If you inherit from Indicator, NinjaScript Generated Code will be added so the indicator can be used in strategies, Market Analyzer Columns, etc.

    If you want to offload some code to another file, you could consider making partial classes in an AddOn.

    Example: https://ninjatrader.com/support/foru...ument-backtest

    I'll also leave the thread open for other community members to share their insight on multi file approaches and what works for them.

    Comment


      #3
      Thanks for fast response Jim.

      I don't think I like the partial class approach -- isn't it really meant for machine generated code or data?

      I can just keep deleting the Ninjatrader generated code at the bottom of the file -- it's only a nuisance until my indi is completed.

      Comment


        #4
        Originally posted by dtl-saw View Post
        Thanks for fast response Jim.

        I don't think I like the partial class approach -- isn't it really meant for machine generated code or data?

        I can just keep deleting the Ninjatrader generated code at the bottom of the file -- it's only a nuisance until my indi is completed.
        Splitting a single class into multiple files is the very raison d'être of c# partial classes. They have nothing to do specifically with machine-generated code. Partial classes as a construct were designed for the kind of very example that you are trying to code.

        ref: https://docs.microsoft.com/en-us/dot...es-and-methods

        Comment


          #5
          Thanks for your response koganam & Jim,
          I went ahead and tried to implement partial classes and got the same error causing behavior from Ninja - i.e. "ninja generated code" generated twice.
          The first compile of the partial classes approach worked fine, but subsequent compiles produced the same double generated Ninja code errors.

          I looked at the example files you linked Ninja_Jim and I'm not doing the exact same thing.
          I would appreciate it if either of you or anyone else could make any suggestions to fix the Ninja code generation errors


          my directory and file structure is as follows:


          ///////////////////
          this file structure compiles and works first time but fails subsequent compiles due to repeated Ninja generated code

          folder = folder1
          filename=file1.cs
          namespace NinjaTrader.NinjaScript.Indicators.MyIndi
          {
          public class MyIndi : Indicator
          {
          code that uses MyClass1 & MyClass2
          }
          }

          folder = folder1
          filename=file2.cs
          namespace NinjaTrader.NinjaScript.Indicators.MyIndi
          {
          public class MyClass1
          {
          code here
          }
          }

          folder = folder1
          filename=file3.cs
          namespace NinjaTrader.NinjaScript.Indicators.MyIndi
          {
          public class MyClass2
          {
          code here
          }
          }


          ///////////////////
          this file structure compiles and works first time but fails subsequent compiles due to repeated Ninja generated code


          folder = folder1
          filename=file_patial1.cs
          namespace NinjaTrader.NinjaScript.Indicators.MyIndi
          {
          public partial class MyIndi : Indicator
          {
          code that uses MyClass1 & MyClass2
          }
          }

          folder = addons
          filename=file_patial2.cs
          namespace NinjaTrader.NinjaScript.Indicators.MyIndi
          {
          public partial class MyIndi : Indicator
          {
          public class MyClass1
          {
          code here
          }
          }
          }

          folder = addons
          filename=file_patial3.cs
          namespace NinjaTrader.NinjaScript.Indicators.MyIndi
          {
          public partial class MyIndi : Indicator
          {
          public class MyClass2
          {
          code here
          }
          }
          }


          Comment


            #6
            Hello dtl-saw,

            I would recommend modelling after the example I linked, and if something is not working well there, to put together some example test scripts that demonstrate what you are doing and the errors received. We could then see the exact errors received and could give some additional insight. Those scripts can be as simple as you have given in post #5 and should not incorporate any additional code, just enough to demonstrate the issue(s) when modelling after the example from post #2.

            We look forward to assisting.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            649 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            370 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            576 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X