NexusFi: Find Your Edge


Home Menu

 





NinjaTrader and DLL's (creating and loading how-to)


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one rleplae with 16 posts (87 thanks)
    2. looks_two laadari with 10 posts (0 thanks)
    3. looks_3 NJAMC with 6 posts (15 thanks)
    4. looks_4 ratfink with 3 posts (8 thanks)
      Best Posters
    1. looks_one rleplae with 5.4 thanks per post
    2. looks_two ratfink with 2.7 thanks per post
    3. looks_3 NJAMC with 2.5 thanks per post
    4. looks_4 sam028 with 1.7 thanks per post
    1. trending_up 29,301 views
    2. thumb_up 121 thanks given
    3. group 23 followers
    1. forum 45 posts
    2. attach_file 18 attachments




 
Search this Thread

NinjaTrader and DLL's (creating and loading how-to)

  #1 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863

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.

Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Exit Strategy
NinjaTrader
Futures True Range Report
The Elite Circle
Are there any eval firms that allow you to sink to your …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
GFIs1 1 DAX trade per day journal
18 thanks
  #3 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


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


Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #4 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863

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.


Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #5 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,394

@rleplae,

Great thread, good detail and pictures... I will refer to this one in the future.

I do believe from memory that NT7 will support .NET 3.5. I know it will not support 4.0+, so you might be able to get a little better .NET than 3.0.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #6 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863

Now we will call a method from the object that we created in our DLL.

Using

We first need to add a using clause to the namespace of the DLL
in our case we used ClassLibrarynexusfi.com (formerly BMT) for our example



Instantiate

Next we create a new object from the object that is defined in the class library



Call method
Now we are ready to use the object and call the public method




When the program is executed the method is called.

Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #7 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863

For those who want to play with the example here is an archive with the skeleton

Attached Files
Elite Membership required to download: ClassLibraryBMT.rar
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #8 (permalink)
 Koepisch 
@ Germany
 
Experience: Beginner
Platform: NinjaTrader
Broker: Mirus Futures/Zen-Fire
Trading: FDAX
Posts: 569 since Nov 2011
Thanks Given: 440
Thanks Received: 518

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.

Thanks Koepisch

Reply With Quote
Thanked by:
  #9 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


Koepisch View Post
Hi @rleplae, 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.

Thanks Koepisch

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

Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
Thanked by:
  #10 (permalink)
 
NJAMC's Avatar
 NJAMC 
Atkinson, NH USA
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
Posts: 1,970 since Dec 2010
Thanks Given: 3,037
Thanks Received: 2,394



rleplae View Post
For those who want to play with the example here is an archive with the skeleton

@rleplae,

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!

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my NexusFi Trade Journal Reply With Quote




Last Updated on December 4, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts