I'm using a technique to automatically connect to an account when NinjaTrader loads that I thought I'd share.
The default workspace is saved so that it will load a single chart with the custom indicator "ControllerIndicator".
ControllerIndicator has a one function, which is to instantiate the singleton instance of NinjaTraderController.
When NinjaTraderController is instantiated, it goes through the following process:
1) Find the window handle of the NinjaTrader control center form
2) Use "Control.FromHandle" to get the current instance of the control center form
3) Using reflection, call the click event handler for the menu item of the specific connection you want to connect to
4) Verify that the connection was successfully opened by checking Cbi.Globals.Connections
I've found this to be much more reliable than using AutoHotkey, and the same technique can be used to automate many other things as well. I use an expanded version of the attached class to add and start strategies, for example.
Notes:
- You will need to change "IQFeed" in the NinjaTraderController constructor to the display name of the account you wish to connect to
- It is assumed that the "Default" workspace is being used, as the window title "Control Center - Default" is looked for
- This is a proof of concept, and I don't recommend using it in a production environment until you have thoroughly tested it
Enjoy,
Marc
Comment