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

Moving Classes to DLL

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

    Moving Classes to DLL

    The indicator I am developing has grown and matured such that it was time to move some classes to a dll. So I did so and added a reference (by right clicking and selecting 'reference' on the indicator chart) to the dll which links to the location of the dll in one of the \projects\ subdirectory under Visual Studio 10. I then added the following line of code to the indicator to incorporate the classes in the dll:

    using xyz; //xyz is the namespace under which all of the classes in the dll reside

    The indicator compiles fine...so far no problem.

    However, when I go to load it, the name of the indicator no longer appears in the indicator list (as it always did before) when I attempt to attach the indicator to a chart.

    What could I have done that causes my indicator to no longer appear (as it always did before) even when it compiles correctly??? No substantive coding changes were made...just moved some classes to a dll.

    I am using NT7 64-bit under W7 64 bit.

    #2
    Try putting the .dll file in the \My Documents\NinjaTrader 7\bin\Custom folder and set the reference for that file in the NT editor.

    Comment


      #3
      I tried that and was surprised that there was no change.

      So I started with my original backed up file and re-made the changes to move classes to a dll. As soon as it successfully compiles, the indicator no longer shows up in the list.

      I then tried this experiment:

      1. I left the dll reference and copied all of the classes back (from the dll) to my indicator source file. I also left the 'using xxx' statement so that the dll would be referenced but would essentially be unused because the compiler will satisfy the class references first from the indicator file.

      2. When I recompiled, the compilation works and the indicator shows up!

      3. Then, I commented out the classes from the indicator file (so that they are picked up from the dll), the compilation works but the indicator does not show up!!
      Last edited by doctore; 10-31-2011, 03:35 PM.

      Comment


        #4
        The "using XXX" tells it to use a certain namespace to look for class definitions, it doesn't matter if that namespace is located in a .dll file or in a .cs file located in the NT indicator directory. The using statement serves a different function than setting a reference in the NT editor. Have you set the reference in the editor by right-click -> References? If not, then you want to add a reference to YourLibrary.dll, which you will want to have in the Documents\NT 7\bin\Custom directory.
        Last edited by lefevreed; 10-31-2011, 05:34 PM.

        Comment


          #5
          Another thing to try, have you tried restarting NT? NT needs to be restarted when adding .dll files that weren't added via the "import NinjaScript" utility. In addition I find it needs to be restarted if the .dll gets recompiled. It seems like the NT compiler will recompile NinjaTrader.Custom.dll into temporary assemblies without the need for a restart, but if something was changed externally, it requires a restart.

          I have done it a couple of ways, I have some utility classes that I have compiled in VS as .dll files, then put them in the NT7\bin\Custom directory and set references and using statements in the indicator file itself as a .cs file that I compile with the NT compiler.

          I have also used the NT "Export NinjaScript" utility, to export all the .cs files (even the additional classes) and exported them all as a single .dll file.

          Both methods seem to work. Although, using the second method the, the indicator file itself, is no longer accessible for editing in the NT editor, it does appear in the list of indicators to apply to a chart.

          I'm not sure if those are the only ways, but that's what has worked for me.

          Ed

          Comment


            #6
            Ed,

            I am using the 1st way you mentioned, that is:

            "I have done it a couple of ways, I have some utility classes that I have compiled in VS as .dll files, then put them in the NT7\bin\Custom directory and set references and using statements in the indicator file itself as a .cs file that I compile with the NT compiler."

            My gut feeling is that, although the compile is completing without errors when referencing the dll, there is something going wrong with the build process that actually creates the 'loadable' indicator, and this process is not giving an error.

            Again, the interesting thing is that when I simply 'uncomment' the classes in the indicator file, all works fine, but of course, that defeats the purpose of trying to move classes to a dll.

            Comment


              #7
              Just to clarify, is the entire "public class YourIndie : Indicator {}", including all the classes in the "NinjaScript Generated Code" region still in the .cs file? And it's only some external classes called from your indicator that have been moved to the .dll file?

              Comment


                #8
                I'll just go ahead with what I would try.

                If you aren't doing it the way I mentioned in my last post, I would first try it that way.

                If that is how you have it set already, what I would try is:
                • Remove the reference to your dll file in the NT editor
                • Copy the .cs files from your VS project and put them in the Custom\Indicator folder
                • Try compiling and testing the indicator with the classes in separate .cs files
                • If that works as expected, then try exporting the .cs files as a .dll file using the "Export NinjaScript" utility.
                • Test it again and see if it works.


                Basically, try taking VS out of the equation, to narrow down the problem.

                Comment


                  #9
                  Removing VS from the equation does the trick and achieves what I was essentially trying to do with a dll, and that is simply to remove the 'mature' classes out of the main indicator file. So just putting them in a separate .cs file file in the \custom\indicator\ folder works fine (i had forgotton NT make available everything in that directory every time you compile any single .cs file).

                  I still don't understand why the dll method is not working, but since the main objective is accomplished, I need to move on.

                  Thanks a lot for your help.

                  Comment


                    #10
                    Any Update?

                    Is there any further information on how to get a custom .dll regognized in NinjaTrader so that it may be accessed from NinjaScript. I have some custom classes written in C# that I would like to access via dll from NinjaScript.

                    Thanks
                    Last edited by Riskybiz; 09-07-2012, 09:38 AM.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by alifarahani, Today, 09:40 AM
                    4 responses
                    20 views
                    0 likes
                    Last Post alifarahani  
                    Started by gentlebenthebear, Today, 01:30 AM
                    3 responses
                    16 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by PhillT, Today, 02:16 PM
                    2 responses
                    7 views
                    0 likes
                    Last Post PhillT
                    by PhillT
                     
                    Started by Kaledus, Today, 01:29 PM
                    3 responses
                    11 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by frankthearm, Yesterday, 09:08 AM
                    14 responses
                    47 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Working...
                    X