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)
I've seen many times how a small helper methods can greatly increase productivity. So the idea for this thread is to share such little code snippets that will extend the existing NinjaScript methods.
In NinjaTrader the simplest way to extend its functionality accross the board (ie: for all Indicators or Strategies) is to include the methods and properties in UserDefinedMethods.cs file, where already an empty partial class is defined.
There are 2 separate UserDefinedMethods.cs files - one for Strategies and one for Indicators so if you have a method you would like to see both in Strategies and Indicators you need to paste the code into both of them.
For Indicator you place the code inside of:
For Strategies you place the code inside of:
Also remember to make all methods and properties you would like to access public, eg.
If you have some cool methods, feel free to post them in this thread!
One example where I've realized I spent too much time is with native Print method.
Firstly I wasted time on formatting and adding prefixes like Time[0], or some identifiers to know where the info came from.
Secondly I wasted time on writing Print, testing, commenting out or removing then writing it again and again.
So I wrote the extension to Print called PrintMe with the following functionality:
You can turn printing On and Off
You can add identifiers such as Time, Name, your own Identifier
You can change the separator for the above parts
You can change the time formatting
You can group messages into different categories/level of depth and decide which ones to display
These properties will be included in any Indicator or Strategy once in UserDefinedMethods and from the code instead of old Print("Some Message") you use:
Here is the code (follow the instructions from first post):
New properties are added to PropertyGrid under category "Debug".
With PrintMe in place I no longer need to comment out any PrintMe, I leave them where they are and if I feel I don't need them for now I simply change the default for PrintToOutputWindow to false in Initialize in the specific indicator. The same with other properties - you can change the default values in Initialize().
I recently learned from @cory, a nice trick to draw symbols with graphic fonts (eg. wingdings).
So I added a custom method where I predefine some symbols I want to use and then call it from Indicator like this:
Here is a code with 2 predefined symbols (one from Webdings and one from Wingdings), just add it to your partial class (eg. UserDefinedMethod.cs) to have it available for all:
For a list of available symbols in both Webdings and Wingdings go to: Wingdings and Webdings!
If you've ever worked with Plot override and custom drawing then you know how painfull the process is with finding the right coordinates. Attached file (ChartHelper) has some nice helper methods to assist you in the process.
PS. I don't know who the original author of the file is.
It seems to me I vastly overestimated usefullness of such thread - as the only people that have shown any interest (thanks) are the ones that could easily deal without my help, plus my hope was to learn something from others as well.
I think I will stop sharing more for now as I feel that I am sharing it with myself
Next time I will decide to share something I will call the thread something more catchy, how about: "Traders are thieves!!!"
I think your thread is a great idea. A couple of quick snippets that come to mind... the beautiful code posted by @Fat Tails to convert to treasury format numbers. Also @Silvester17 has posted a treasure trove of little gems as well. Hang in there - right now, indicators and t/a have been dismissed here in favor of using vix, usd/jpy, bonds, and the fed to "form a market opinion" and then based on that you guess what the market will do and trade accordingly. That will pass. What the market is actually doing is far more important than what someone thinks it should do, or might do, etc. Thanks for your contributions.