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)
Some coding practices when using VS with NinjaTrader
I have recently joined BigMike's forum and I would like to contribute some of my experiences in using Visual Studio along with NinjaTrader. Some of these have been possibly mentioned by other forum users before, nevertheless if so I hope that's ok.
I have been experimenting with Ninjatrader for a short while. My aim was to be able to call a class library from NT script. By error & trial(note that I used some forum discussions and tips as well), I came upon some steps that needs to be taken carefully, in order for a script to work properly. Below I would like to share the conclusions of some of my experiences.
1-Always compile your class libraries into c>users....>MyDocuments>NinjaTrader7>bin>Custom. If compiled somewhere else, it works sometimes but not all the time. I don't know the internals of NT well enough to explain this.
2-Place your project under the same directory. (I am using Win7 pro)
3-Use Net 3.5 for your class library.
4-Create the template of your indicator always in NT (NT creates bunch of extra C# code)
5-When adding your indicator into VS project add it as "Link"
These are the ones coming into my mind at the moment. Feedback/corrections are welcome and I hope it may help others.
Would be very interested in learning about some of your applications of these techniques.
I don't know if this would be one, but I would like to be be able to use an object that is just like the DataSeries object, but has a fixed, user defined number of elements - with a fixed element count, it could be based on the C# array, rather than the list.
This would be perfectly adequate for many places where the DataSeries is used, with a big reduction in memory and CPU consumption since the number of elements to be managed would often be much less than 256, and much less than the number of bars on the chart.
Another worthy goal would be the ability to create an object that works just like an instrument but is based on the weighted sum of more than one instrument. Yes, this can be done in an indicator, but having something that behaves just like a regular instrument would have some advantages.
(While I am good at making Ninjatrader indicators run efficiently, my mastery of C# is narrow and limited.)
"If we don't loosen up some money, this sucker is going down." -GW Bush, 2008
“Lack of proof that something is true does not prove that it is not true - when you want to believe.” -Humpty Dumpty, 2014
“The greatest shortcoming of the human race is our inability to understand the exponential function.” Prof. Albert Bartlett
For anyone reading this thread, there is another thread which I would like to re-iterate here. The thread is called NT & VS for Dummies and includes very useful information. Check it out (
I'm now the proud owner of the full version of Visual Studio 2010, having played with VS Express versions for C# and C++, as well as Eclipse for C++ over the past few months.
I'm starting this thread as I learn from scratch what works and doesn't …
)
Secondly, I managed to crash today NT completely. Well, this may be one of the side effects of using Visual Studio. You got to be very careful, especially with NT DLLs (like .Core), meaning where you place them etc. I am planning to write a thorough document for myself, in order to follow it up at the next crash. I will post it here as well, for anyone willing to use it as a first aid reference. Coming back to today's crash. I was copying some existing classes into my class library (the one I am using in my indicator). The classes I imported required NT DLLs as reference. As sson as I imported the DLLs into th reference of the library project, boom sth. happened and the next time I hit F5, NT wasn't launching. I couldn't even launch NT standalone. Error log was directing me to NinjaTrader.Core.DLL. I had to totally scrap NT from my computer (yes, uninstalling first thru windows and then completely erasing all leftover NT Folders from Windows Explorer). My assumption is that possibly I have referenced a copy of the NT Core DLL which was residing somewhere else in my computer (It dawned on me, after I wiped out NT though). So the lesson learned is: When using NT along with VS, one should be extremely tedious and keep all the references in a VS solution same (meaning you only use one NT DLL location). Tomorrow I will go through the process again to link NT back to my class library (following the post listed above).
Tomorrow I will also try to use a static class within my class library to see if it works. The reason being is that I would like to pass variables to and from my main C# business model to NT without the need of class instantiation. That would remove the need of passing class object reference. Well, I'll see how it will work.
Once in VS, anything can be done (well that what I assume at the moment at least). My approach is to use NT script with minimum code and use class libraries to do what I would like to do. So NT Script is just a front end which provides some basic info to my business model running in the background. I will only post some annotations on chart display reflecting the computed outcome of the background machine. Therefore I need a very stable link in between my VS Class libs and NT.