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)
Does anyone have a preferred method of re-using common code (or code snippets) in NinjaScript?
Back when I used to write real code, I could embed a file which the compiler would pull in and place inline before compiling, so I could re-use common sections without replicating the same lines in multiple places. I would love to be able to do that in NinjaTrader.
I have written separate namespaces, with custom classes, and saved/compiled the script in the Indicator directory. Then added "Using name;" with the others at the top of the Indicator script that used the class. However, since the namespace isn't built off the Indicator code, I haven't figured out how to use Print() or any of the NinjaScript functions.
Likewise, I can write a static class that can be used by any other without forcing an instantiation, but it has similar limitations.
What solutions have others used?
Can you help answer these questions from other members on NexusFi?
I ran into the problem yesterday of not being able to use Print, I'm sure there's some global object for the output window we need to get our hands on, but I don't know what it is.
My solution was intrusive but if I really need to communicate an error condition, I found that calling System.Windows.Forms.MessageBox.Show works.
In your custom code accept the NT Strategy/Indicator object as a parameter to the constructors. You can then call the NT functions from your code via the handle you have to the NT data-structures.
I have wondering about the resource consumption by instantiating (calling a constructor) a class simply to re-use common code. NT is not the most efficient compiler in the world and I wonder about excess memory consumption and performance impacts. Up til now, the only methods I moved to a separate class were those which could be static, so no instantiation (construction) is required to call them.
I know one person got around not having the NT Draw routines by overriding the chart plot routines and creating his own.
You can profile your NinjaTrader C# NinjaScript code (indicators and strategies) to fine tune their performance using Visual Studio 2010. You will need the full version of Visual Studio 2010.
The wiki will automatically insert a table of contents …
Thanks Mike. I was actually looking at some Visual Studio links earlier -- it would be nice but I don't have Visual Studio and haven't quite figured out how much it costs, which version do I need, etc. One day I plan to get there.
So I started this thread hoping to encourage folks to share techniques that work with just NT. :-) For poor folk like me!
VS 2010 Pro has some of that functionality and costs between $0-$500 depending on your use. I'm on the road now but that will be the subject of the next update in my "NinjaTrader and VS2010 for Dummies" thread when I'm back.
Basically you can create and edit your own Code Snippets for custom methods, etc which saves typing. The IDE also knows your file-specific variables, etc and can auto-fill them for you as you type.
OK, I separated out the Visual Studio discussion to a separate thread because I do not want it to stop, but I do want to keep this thread on topic. So please bear with me.
If anyone has examples of C# common code re-use that they would liketo share, or more techniques that can be implemented in a NinjaScript cs file, please chime in!
I'll see if I can dig some out. I know that they are not "officially supported" so use at your own risk. But it is a great way to learn.