Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
This thread is a "how to" for creating a DLL (dynamic link library) that can be loaded into NT (NinjaTrader).
A DLL is a compiled component that can hold various objects (classes) in a namespace.
Many of the system functions and objects that can be created in c# are implemented through DLL's
A DLL with classes is called a classlibrary.
A few reasons why somebody would want to create a DLL :
Library reusable objects
Often used classes/objects or methods can be organized in a more efficient way by bundling them in a class library. This is a far better method in software design than copying the same lines of code over and over in the .cs source files. Otherwise when a bug needs to be fixed, it needs to be done on many places (as many times as the function was copied in various source files) and with the risk of forgetting one. When using a class library there is a central place to fix the bug in the code and to maintain the code
Usage Inside and Outside NT
Imagine you have some objects that you want to use both inside NT (in an indicator or a strategy) and outside NT (with a stand-alone back testing program, ...), Then the creation of a DLL makes it possible to isolate the classes in a module that can be loaded and with a clear interface.
Protecting Source code
Creating a DLL is a first step if you don't want to give the source code to somebody but still want to offer the functionality. Keep in mind that you might need to take additional steps in order to protect your module from reverse engineering, just compiling is not enough.
In order to create a DLL you will need a development suite.
One of the most popular development environments is Visual Studio from Microsoft.
The example in this thread was created with the free version of the Microsoft Visual Studio Express for Desktop.
There are many other version that can provide the same result.
The first thing we will do is creating a project in VS (Visual Studio) for the class library we want to create.
That is fairly easy and straightforward because VS comes with a template and knows how to create a class project.
Withing VS we have chosen "File" -> "New Project"
and we have filled in some naming and folder information where to create the project.
This is how the screen looks like :
After we confirm the OK button the project is automatically created and shown as follows :
Unfortunately VS has created this project automatically to support .NET 4.5 version or newer depending on the version of your VS. However NT 7 uses .NET 3.0.
So the next step is to 'downgrade' the target framework to .NET 3.0
This can be done, by double clicking on properties and a window will open like the next screen.
Next you need to confirm the operation
The next step is to clean the project due to the downgrading to targetplatofmr .NET 3.0
open the references and delete those with an exclamation point :
in the source code we also need to remove thwo usings that do not exist in .NET 3.0
After the previous little cleanup step it becomes like this
We can now add objects and methods
For the purpose of the next steps in NT we create a simple Object and simple Method than can be called.
We are now ready to compile and build our first DLL, after pressing F7, there are no compile erros
and we have created a DLL file
In the previous post we have seen how to create/build a DLL
Now we will install the DLL that was created in NT
This is a fairly straightforward process
Copy the DLL
First we need to copy the DLL file to the custom directory of our NT install
This is typical in the folder : Documents/NinjaTrader 7/bin/Custom
Simply copy the created DLL file into that folder
Reference the DLL
The next step is to go into any random indicator or strategy cs file
right click on the background of the source file select "References" from the pop-up window
In the next screen click the add button
Browse for our "ClassLibrarynexusfi.com (formerly BMT).dll" file that we created
The DLL is now correctly referenced and added to NT and ready to be used in our source files.
Hi @rleplae, i very appreciate your contributions. I'm sure that it will help a lot of people having the same tasks. I like the many pictures, because it helps visualize the stuff and then it's far better to understand.
I want to make an suggestion for an issue i'm facing currently. I want to raise an event within NT (execute function within NT) from my dedicated C# solution. In my external solution i have imported the OHLC data from NT and running my trading logik. As results i have the trade setups and backtesting statistics. NOW i want to select single trades in my program and want to control NT to scroll the trade location in the center of the chart view. I could do it via an POLLING pattern at OnBarUpdate but i don't want go this way for various reasons. I'm still searching an BM for related Posts, but i think it will match this thread too.
@Koepisch Thank you for your appreciation
I think we would go too far off-topic to discuss your particular problem in this thread, but I will be happy to brain-storm with you, in a dedicated thread. To my knowledge NT does not have published "api" to scroll the chart or position the chart.
This thread is about how to create a DLL and install and use it in NT.
Any questions and problems encountered, making abstractions of what exactly you want to do in the DLL are welcome on this thread.
What a well done tutorial. I would almost like to recommend you make a small eBook as a reference. You definitely have the skills and patients to explain some of the very detailed activities! This is a treasure for the site!