Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

technique to automatically connect to account on launch

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    technique to automatically connect to account on launch

    Hello,

    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
    Attached Files

    #2
    Hi Marc, thank you for this. Of course, this is all unsupported, so don't expect help from us if something goes wrong.

    NinjaTrader 7 has addressed this:


    New Automatic Connect on Application Start Up
    You can enable any defined connection to automatically connect when you start NinjaTrader.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Hi Austin,

      I definitely understand that I assume all risk as this is unsupported, and I look forward to the release of NinjaTrader 7.

      Thanks,

      Marc

      Comment


        #4
        Hi Austin,

        good work, thank you!


        Please keep posting!

        I also use the undocumented NinjaTrader functions extensively. It is compulsory to do so to implement full automation and full flexibility.


        To get the Control Center I just use

        string title = "Control Center - ";
        foreach (Form frm in Application.OpenForms){
        if (frm.Text.Contains(title)) {
        EnumWindows eW = new EnumWindows();
        eW.GetWindows(frm.Handle);
        foreach (EnumWindowsItem item in eW.Items){
        Control c = Control.FromHandle(item.Handle);

        if(c!=null && c.GetType()==typeof(SourceGrid2.GridSubPanel)) {
        SourceGrid2.GridSubPanel sgp=c
        as SourceGrid2.GridSubPanel;
        SourceGrid2.Grid g=sgp.Grid
        as SourceGrid2.Grid;
        ...
        ...




        I also use autoHotkey, but only to get my backfill, so I launch Ninja every day at 7.30 am just to do all backfill activity. Up to now autohotkey is reliable, but my autohotkey script takes into account whatsoever popup window comes around.


        Best regards
        Andreas

        Comment


          #5
          Hi Andreas,

          Thanks for the feedback.

          Enumerating through Application.OpenForms is definitely a better method than using P/Invoke.

          In the next few days I'll be posting a revised version of this class which will be able to add and start strategies. I have this in place currently, but it is setup for a specific strategy I use -- I just need to refactor it to be able to load any strategy.

          I'll send you a private message once I've posted it; I'm always interested in feedback, and I'm very interested in seeing how other programmers are taking full advantage of the ability to automate NinjaTrader.

          Best,

          Marc

          Comment


            #6
            Originally posted by marc.newlin View Post
            Hello,

            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
            --Marc , can you export this script and upload it ? i tried this .cs file but it gives error. many thannks

            Comment


              #7
              Hi Marc,

              you are Marc ! and not Austin,

              good work and I am looking forward to hear from you.

              andreas

              Comment


                #8
                Hello,

                Attached is an updated version of this class with the ability to add strategies. To use it, do the following:
                1. Add the NinjaTraderContoller.cs file to the NinjaTrader.Custom project if you are using Visual Studio. If you are using the NinjaTrader editor, create a new indicator called "NTController" and copy and paste the C# code from the NinjaTraderController.cs file.
                2. In the top of the NTController class, you will see two constants, AccountDisplayName and AccountName. Set these to correct account names you wish to use. Do not use Simulated Data Feed as it will popup a message box which will block and interfere with loading the strategy.
                3. Save and compile the indicator
                4. Setup the default workspace so it contains only a single chart, with the indicator NTController. Please make sure you just have the one chart set to load with the default workspace. If you have additional charts they will block while the NTController constructor is running and prevent the New Strategy dialog from being displayed.
                5. Close and restart NinjaTrader, and it should now connect to your account, and, in this example, add an instance of the SampleMACrossOver strategy.


                The code to add the strategy and assign its properties is currently located in the NTController constructor. It should be pretty straight forward, but let me know if you have any questions.

                This can be easily modified to connect to multiple accounts, flatten the accounts on startup, load multiple strategies, etc.

                I will be posting another version sometime next week with some additional functionality including loading charts.

                Best Regards,

                Marc

                DISCLAIMER This is just a proof of concept and has not been tested. Please do not use it in a production environment until you have familiairized yourself with how it works and have tested it.
                Attached Files

                Comment


                  #9
                  Hello,

                  I should also note that this will only load InstrumentType.Currency instruments, but if you look in NTController.AddStrategy, you will see that it can be easily changed to load any type of instrument.

                  Marc

                  Comment


                    #10
                    Ray,

                    This is what I am talking about. It's just so negative and annoying.

                    "Look out of the boogie man"

                    I mean what kind of comment is that. You think this poster who made this awesome contribution is motivated to do so again?

                    This is not in the best interest of NT in my personal opinion. I can only speak for myself, but I there are others who I have spoken with who are feeling the same way.

                    Why didn't Austin say thank you, and then give direction for how to add to code snippets and/or move it there for us to find?

                    It's your company, but it's made up of us.

                    Originally posted by NinjaTrader_Austin View Post
                    Hi Marc, thank you for this. Of course, this is all unsupported, so don't expect help from us if something goes wrong.

                    NinjaTrader 7 has addressed this:


                    New Automatic Connect on Application Start Up
                    You can enable any defined connection to automatically connect when you start NinjaTrader.

                    Comment


                      #11
                      Marc,

                      I just wanted to personally thank you for this contribution. There have been many members working to resolve this very issue. If you can PM me, I would like to know more about how far you got with this.

                      While I understand NT7 has some of what your code addresses, that will be of little use for those strategies that are tightly knit to NT6.5 and can't be converted straight away. In the meantime, your code provides a nice option.

                      I was spying the forms to try to get to the namespaces and classes you found, etc., so I really appreciate this.




                      Originally posted by marc.newlin View Post
                      Hello,

                      I should also note that this will only load InstrumentType.Currency instruments, but if you look in NTController.AddStrategy, you will see that it can be easily changed to load any type of instrument.

                      Marc

                      Comment


                        #12
                        Andreas,

                        CAN YOU BELIEVE THE REPLY AUSTIN GAVE?

                        How many people have been looking for this? And Austin just snubbed him.

                        Ray,

                        We need a real developer wiki and better organization. This is unnacceptable.

                        Why wasn't this work moved and documented in the code snippets. Do you know how valuable this is to people WHO ACTUALLY TRADE REAL MONEY!

                        Do you know how easy it is to link to the wrong account or wrong instrument?

                        I seriously can't believe what Austin said and this little gem of code has been parked here all along since June.

                        On top of that, your support team has been responding to questions about this very issue and never once NEVER ONCE did they direct anyone to this thread.

                        PROPOSAL:
                        Developer Wiki, Sell Developer License, Hire one person to expose more of NT and manage the Developer Wiki and assign moderators.

                        I'm I alone here ? Any other developers feeling this pain?



                        Originally posted by zweistein View Post
                        Hi Marc,

                        you are Marc ! and not Austin,

                        good work and I am looking forward to hear from you.

                        andreas

                        Comment


                          #13
                          r2ktrader,

                          Austin for sure could have handled his response better and I will discuss this with him.

                          I provided you my position in another post which you have read. We don't support or promote undocumented aspects of our product.
                          RayNinjaTrader Customer Service

                          Comment


                            #14
                            Ray,

                            I will support you in that stance, provided you increase the level of documented aspects. The level now is simply not acceptable.

                            Please listen to me in this regard. I know many others feel this way. Do you know how many people have been trying to automate better in 6.5?

                            I trade with real money Ray. Do you know what the partners said when I started a strategy on the bonds one morning when I meant to start it on the ES? They would have laughed at me had it not been for the fact we lost money. Far more than it would cost to buy a developer's license.

                            I needed a solution to nail up strategies. I am over here working on keyboard macros and crap like that, and here Marc provided an elegant solution and it's buried deep in the forums of purgatory?

                            My fear is that I will have to abandon NT and go full black box. Our models are not complex and Rithmic is getting a lot of traction and once everyone realizes that ZenFire is simply a reseller of them, their API will get more traction. I know some really bright people are working on it as we debate.

                            1. Do your "consultants" get access to more information to provide solutions for your clients, or are they equally limited regarding documetation?

                            2. Can I buy a developer's license. I will gladly pay 1500-2500 to get access to look under the hood. Object spying is a pain in the tail and a waste of time. I'm tired of walking through the alphabet via intellisense to sniff things out.

                            3. If I were to take it upon myself to setup a development wiki, would you be willing to provide more information regarding the classes and namespaces?

                            Thank you again for taking time on this. I was very angry after finding this thread and feel like a complete idiot and fool barking up the wrong tree on nailing parameters. Not only that, I get angry when it is now clear to me that the very issue I was trying to resolve, had a solution, and not one of the support team, in and through NUMEROUS posts and exchanges, ever once pointed me to this thread. The closest I came was another member who wanted to sell me this solution for 1500.00. (which seemingly was based on this very code with some enhancements.) (This should have been in code snippets.)

                            In closing, I know you have 7 on your plate, and I appreciate you taking the time to respond, that is first class. I don't want to be rude by taking anymore of your time while the many are awaiting NT7, which will address many of the issues I have been struggling with.

                            Sincerely,

                            UPDATE:
                            My hunch is that you are getting the majority of your revenue from a rev-share with brokers and as such your object is to cater to the lowest common denominator, namely the retail trader. Thus is doesn't benefit you to focus attention on the development side as much and at that point C# just becomes a convenient scripting language rather than a true developement tool.

                            With that being said, please just help me to know so I don't waste your time or mine. If your model is X, and I am looking for Y, there is no reason for me to grow frustrated and you waste your time responding to posts like these. Before I sign the divorce papers, I just want to be sure our differences were not a misunderstanding.





                            Originally posted by NinjaTrader_Ray View Post
                            r2ktrader,

                            Austin for sure could have handled his response better and I will discuss this with him.

                            I provided you my position in another post which you have read. We don't support or promote undocumented aspects of our product.
                            Last edited by r2kTrader; 11-05-2009, 11:15 AM.

                            Comment


                              #15
                              actually I had also PM communcication with marc newlin some month ago.

                              These solutions are tricky and the snippet was far from finished but a very nice piece of code. Using this code NT might freeze in cas certain forms are open. You can easily end in the classical multithread race condition.

                              Andreas

                              if you are interested in Ninjas internal working just use the Visual Studio 2008 environment or similar. You can browse all the classes. But all this in just plain vanilla C# .Net and has nothing to do with NinjaTrader.
                              Best for you is to hire a guy locally. Try to find marc.newlin, I think he lived in Florida.
                              @r2ktrader:

                              I was offering something different to you, which was strategy parameter persistance relative to the instrument used for NT 6.5.
                              We never talked about automatic connection at startup.
                              Last edited by zweistein; 11-05-2009, 11:23 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by mgco4you, Today, 09:46 PM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by wzgy0920, Today, 09:53 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post wzgy0920  
                              Started by Rapine Heihei, Today, 08:19 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by Rapine Heihei, Today, 08:25 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post Rapine Heihei  
                              Started by f.saeidi, Today, 08:01 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X