• 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.


No announcement yet.

Partner 728x90


Best Approach to Export Indicator that Uses a standalone C# Class

  • Filter
  • Time
  • Show
Clear All
new posts

    Best Approach to Export Indicator that Uses a standalone C# Class

    1) How to export an indicator that depends on another plain old class object?

    In trying to export an indicator I've created, I'm trying to determine the best approach because it depends on another class in a separate file.

    I've done all of this in the standard Custom project. The class is a simple basic class having nothing to do with NinjaTrader.

    I don't see a way to include code unless it's a special NinjaTrader component like an Indicator or Strategy or unless it's a DLL reference.

    Do I need to put my class in a separate project and reference the DLL in order to get exporting to work?

    2) Is it possible to create ninjascript objects, like indicators and strategies, in a separate DLL that is then referenced in NinjaTrader?

    Is this do-able so long as our separate project references all of the necessary NinjaTrader DLLs including NinjaTrader.Vendor.dll? Then when
    we deploy the DLL to the custom folder we just copy the main DLL and not the references because they are, theoretically, already referenced
    by NinjaTrader?

    What is the primary purpose of the NinjaTrader.Vendor.dll?

    What is the recommended location from which to reference those DLLs? The custom/bin area in MyDocs? Or the NinjaTrader
    installation folder in Program Files, C:\Program Files (x86)\NinjaTrader 8\bin\Custom\Backup ?

    3) What if the dependencies are not just plain old C# classes but are say, extensions for the NT Instrument class?

    I have a lot of extensions to NT classes which I use in indicators and strategies. How can I include these in an export of an
    indicator? Can they be added to that separate project? That project would require a reference to NinjaTrader.Core which contains the Instrument class. Would that work? Is that sufficient, recommended?

    4) If I'm creating multiple indicators which all depend on some common classes, what is the best approach?

    I could have a common DLL that is used by multiple indicators, but if I export each indicator individually they'll each depend on the same DLL.
    Will there be problems if the indicators are imported separately, with that same DLL added to each .zip file? Will their common dependency be handled gracefully without trying to add multiple copies of the DLL?

    Or, would it be best to export all indicators in a single export package?


    Last edited by BarzTrading; 01-27-2019, 10:03 PM.

    Hello BarzTrading,

    When exporting a closed source assembly with scripts that use a shared class, this should be exported in a separate file and should be referenced in the export.

    Below is a link to a video I have created that demonstrates.

    NinjaTrader does not support classes that extend NinjaTrader classes such as Indicator or Strategy.
    This thread will remain open for any community members that would like to assist with this unsupported code.
    Chelsea B.NinjaTrader Customer Service


      Thanks for the video, Chelsea. It answered several of my questions. A couple remain.

      So, if the dependency is a code file, a plain class, rather than an indicator as you demo'd, would I be correct that I have two choices?

      1) I could drop one or more *.cs files into the zip file?
      2) I could use Visual Studio to create a separate project which produces a DLL that can be referenced by NinjaTrader.


        Hello BarzTrading,

        Yes, the instructions in that video apply to all classes (no matter what other class they happen to be extending such as Indicator or Strategy or if its just a class in an Addon)

        The idea with the video is that the shared class would also be exported as a dll, but sure if you wanted to include open source .cs files with the export these can be selected in the export window. (Open source scripts will import to specific folders so these should be added using the Tools > Export > NinjaScript Addon window)

        Yes, you can create a dll in Visual Studio, create a reference to in the NinjaScript Editor and compile, then when exporting include a reference to the dll, then drag and drop the .dll file in the exported .zip file.
        Chelsea B.NinjaTrader Customer Service


          Thanks, Chelsea.

          I understand the video and can replicate it. What I don't understand is how you would include a random *.cs file that contains a plain old c# class (a shared class). When I use the export operation I have no option to select individual source code files.


            Hello BarzTrading,

            Is the open source script in NinjaTrader? Can you open it in the NinjaScript Editor?

            If so, it should be available in the export window.

            What folder is it in? Is it in the Addons folder?
            Chelsea B.NinjaTrader Customer Service


              I've added my common classes in a folder called Barz at the same level as /AddOns, /BarsTypes, /ChartStyles, etc.

              This folder does not show up in the NinjaScript editor. I always use Visual Studio so I hadn't noticed that.

              The common classes are using the Barz namespace.

              I put my indicators in the folder /Indicators/Barz and use the namespace: NinjaTrader.NinjaScript.Indicators.Barz. This works fine and I can see these and edit them in the NinjaScript editor.

              I don't know if namespace is relevant here, but where should the class files go?



                Hello BarzTrading,

                I would advise against creating a new folder in the Documents\NinjaTrader 8\bin\Custom folder.

                Instead, add any custom classes to the Addon folder.
                Chelsea B.NinjaTrader Customer Service


                  That's it, Chelsea! I moved all my code under the AddOns folder and all of the files are now recognized in the Export dialog as "Add On" items.
                  Last edited by BarzTrading; 01-28-2019, 12:14 PM.


                  Latest Posts


                  Topics Statistics Last Post
                  Started by glennts, Today, 08:24 PM
                  0 responses
                  1 view
                  Last Post glennts
                  by glennts
                  Started by ibabinov, 11-12-2019, 09:50 AM
                  3 responses
                  Last Post NinjaTrader_ShawnB  
                  Started by PrimoItch, 05-27-2020, 04:35 PM
                  2 responses
                  Last Post bkonia
                  by bkonia
                  Started by RuthB, Yesterday, 09:41 PM
                  1 response
                  Last Post NinjaTrader_ChrisL  
                  Started by Newtrader101, Today, 12:12 PM
                  3 responses
                  Last Post NinjaTrader_ShawnB