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

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

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

Collapse
X
  • 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?

    Thanks,





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

    #2
    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.
    https://drive.google.com/open?id=1D9...0R7caTu0icg9nC

    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

    Comment


      #3
      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.

      Comment


        #4
        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

        Comment


          #5
          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.

          Comment


            #6
            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

            Comment


              #7
              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?

              Thanks,

              Comment


                #8
                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

                Comment


                  #9
                  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.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by saeed, Today, 12:32 PM
                  3 responses
                  27 views
                  0 likes
                  Last Post NinjaTrader_PatrickG  
                  Started by motog4, Today, 11:42 AM
                  3 responses
                  16 views
                  0 likes
                  Last Post NinjaTrader_PatrickG  
                  Started by derivtrader, Today, 11:20 AM
                  5 responses
                  27 views
                  0 likes
                  Last Post derivtrader  
                  Started by TAJTrades, Today, 10:34 AM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Started by timcjpfx, Today, 10:20 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Working...
                  X