NinjaTrader and DLL's (creating and loading how-to) - NinjaTrader Programming | futures io social day trading
futures io futures trading


NinjaTrader and DLL's (creating and loading how-to)
Updated: Views / Replies:9,197 / 44
Created: by rleplae Attachments:18

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 18  
 
Thread Tools Search this Thread
 

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

  #1 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,487 since Sep 2013
Thanks: 1,702 given, 3,690 received
Forum Reputation: Legendary

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

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.


Last edited by rleplae; August 22nd, 2014 at 10:03 PM.
Reply With Quote
The following 19 users say Thank You to rleplae for this post:
 
  #2 (permalink)
Quick Summary
Quick Summary Post

To create a DLL you will need a development suite:
http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx

This procedure is valid for NT 7.0

I make reference below of NT only supporting .NET 3.0, but like @NJAMC correctly pointed out, you can use .NET 3.5 when downgrading the target platform.


Last edited by rleplae; August 22nd, 2014 at 10:06 PM.
 
  #3 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,487 since Sep 2013
Thanks: 1,702 given, 3,690 received
Forum Reputation: Legendary

Creating a class library


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 :

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


After we confirm the OK button the project is automatically created and shown as follows :

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


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.


Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).



Next you need to confirm the operation

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


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

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


After the previous little cleanup step it becomes like this

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


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.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).



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

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Reply With Quote
The following 19 users say Thank You to rleplae for this post:
 
  #4 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,487 since Sep 2013
Thanks: 1,702 given, 3,690 received
Forum Reputation: Legendary

Loading a DLL in NT

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

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


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

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


In the next screen click the add button

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Browse for our "ClassLibraryfutures.io (formerly BMT).dll" file that we created

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


The DLL is now correctly referenced and added to NT and ready to be used in our source files.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Reply With Quote
The following 14 users say Thank You to rleplae for this post:
 
  #5 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 received

3.5 .NET

@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
Reply With Quote
The following 3 users say Thank You to NJAMC for this post:
 
  #6 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,487 since Sep 2013
Thanks: 1,702 given, 3,690 received
Forum Reputation: Legendary

Using objects form our DLL

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 ClassLibraryfutures.io (formerly BMT) for our example

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Instantiate

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

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


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

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).



When the program is executed the method is called.

Reply With Quote
The following 13 users say Thank You to rleplae for this post:
 
  #7 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,487 since Sep 2013
Thanks: 1,702 given, 3,690 received
Forum Reputation: Legendary

VS Project archive

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

Attached Files
Register to download File Type: rar ClassLibraryBMT.rar (12.1 KB, 98 views)
Reply With Quote
The following 7 users say Thank You to rleplae for this post:
 
  #8 (permalink)
Elite Member
@ Germany
 
Futures Experience: Beginner
Platform: NinjaTrader
Broker/Data: Mirus Futures/Zen-Fire
Favorite Futures: FDAX
 
Posts: 440 since Nov 2011
Thanks: 254 given, 369 received

Event Sink

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
The following 2 users say Thank You to Koepisch for this post:
 
  #9 (permalink)
Elite Member
Omer עומר / Israel י
 
Futures Experience: Master
Platform: NinjaTrader, Proprietary,
Broker/Data: Ninjabrokerage/IQfeed + Synthetic datafeed
Favorite Futures: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,487 since Sep 2013
Thanks: 1,702 given, 3,690 received
Forum Reputation: Legendary

DLL thread


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.

Reply With Quote
The following user says Thank You to rleplae for this post:
 
  #10 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 received



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
Reply With Quote
The following 6 users say Thank You to NJAMC for this post:

Reply



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

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use NTDirect.dll or NinjaTrader.Client in NinjaScript? vantojo NinjaTrader Programming 7 January 15th, 2014 06:39 AM
Interactive Brokers Gateway / Ninjatrader not loading weekly and monthly charts? luvs321 NinjaTrader 3 January 10th, 2014 02:05 PM
How-to remove .dll files from NinjaTrader PandaWarrior NinjaTrader 7 October 1st, 2012 08:21 AM
Please help creating a NinjaTrader Indicator jjl1753 NinjaTrader Programming 4 June 13th, 2011 10:26 PM
External DLL from Ninjatrader ehlaban NinjaTrader Programming 11 June 13th, 2010 12:42 PM


All times are GMT -4. The time now is 11:47 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-12 in 0.16 seconds with 20 queries on phoenix via your IP 54.234.255.29