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

Using windows Form instead of file io

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

    Using windows Form instead of file io

    I am currently using a file to pass information between an application I am developing with Visual Studio C# Express and NT. My life and my application would be much better if I could run this all from NT instead.

    I'm trying to define a form class and use it but so far I am unsuccessful. Questions:
    1) Is this this possible?
    2) If not, is there a better way than file io available to communicate with NinjaTrader?

    Here is the code I used. It gets an error "The type of namespace 'TestForm' could not be found."

    public class FormsTest : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)

    //define class for test Form
    public class testForm : Form
    {
    //constructor
    public void TestForm()
    {
    //commented out for now
    //this.Text = "this is a test Form";
    }
    }
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    TestForm display = new TestForm();
    }

    Thanks!

    Folls

    #2
    1) Yes this is possible since this is C# and .NET but it is outside the scope of what we are able to provide support for. I have seen others create some very creative custom windows to drive information to various NinjaScript objects. Maybe someone here can help. You can always contact one of our NinjaScript consultants who could help you in this area as well.

    2) Same answer as above.

    RayNinjaTrader Customer Service

    Comment


      #3
      Just one example?

      Thanks. Maybe Ninja (or anyone) can post one simple example so everyone can see how it's done. You don't need to support it from that point. One simple example to get started would be very valuable.

      Folls

      Comment


        #4
        First of all, when developing forms for use with NT I have found that it is more convenient to develop the actual forms in Visual Studio, compile the form code into a DLL and add a reference to that DLL from NT. That way you have all the wysiwyg tools of VS at your disposal which makes forms development much easier.

        Now, that being said your way should work as well. From the code you posted it seems your problem might be that you named your form class with a lower case starting character: testForm rather than TestForm. And of course you would have to call the Show() method of the form after you instantiate it to actually see anything

        However, I think you will find that showing a form in the Initialize method of a strategy will not be practical as Initialize gets called multiple times before a strategy is ever put on a chart. I have yet to sort out exactly how and why.

        Comment


          #5
          Thanks for the advice. I will pursue the dll method. As you probably guessed, I am new to C# programming. I can use all the help I can get so I appreciate your assistance!

          If I can get a form to work, I'll post a simple one in this forum for future use by others. If anyone has one they would like to post, please do so.

          Thanks!

          Folls

          Comment


            #6
            Strictly speaking, you might not even need a DLL. As far as I can see, you could just copy the source files from your Visual Studio project to one of the NinjaTrader Custom folders, but I have not been experimenting with that, so I cannot tell if that will cause any problems or inconvenience.

            One disadvantage to using the DLL method however, is that in order to update the DLL you would have to close NT, as it will lock the DLL when it loads it.

            Using Visual Studio will also allow you to explore the NinjaTrader.Core DLL which contains all kinds of unsupported goodies.

            For example the chart form that a strategy is running on is a standard Windows.Forms form with Windows.Forms controls on it. Therefore you can manipulate it programmatically, such as adding buttons to the ToolStrip.

            Comment


              #7
              >> For example the chart form that a strategy is running on is a standard Windows.Forms form with Windows.Forms controls on it. Therefore you can manipulate it programmatically, such as adding buttons to the ToolStrip.

              This is not supported and we strongly recommend not doing that, since it could throw up NT internal operations.

              Comment


                #8
                Yup, just wanna emphasize that something like that is definitely not supported. And if you encounter any issues with your strategies you will need to clean out that part of your code as one of the first things to try.

                You need to know what you are doing and be very careful with your testing.

                Also, any time you use something unsupported, there is no guarantee that it will not break with the next release of NT.

                Comment


                  #9
                  Correct. Your clarification is appreciated.

                  Comment


                    #10
                    Only an empty form shows

                    I'm making progress in pursuing the dll based solution but could use some more advice. Here is a summary of what I did so far.

                    I created a simple windows forms application with one button in Visual Studio 2005. I then changed the output type in Visual Studio under properties to class library to generate a dll. I put the dll in the mydocs Ninja Trader Custom folder. I created a new strategy, added the using statement, added a new reference to the dll, and created a new instance of the form object in the Ninja Trader Initialize section.

                    protected override void Initialize()
                    {
                    CalculateOnBarClose = true;

                    //added by me to test creating a form from the dll
                    Form1 dllTest = new Form1();

                    }

                    I then put the strategy on a chart. A window does pop up but it is empty. The button I created does not show up.

                    Is there something that I'm missing to make the whole form I created in Visual Studio appear?

                    Any help would be great! When I get something simple working, I'll document it and post it here for all to share.

                    Thanks,

                    Folls

                    Comment


                      #11
                      do you call the form show method?

                      dllTest.Show();
                      RayNinjaTrader Customer Service

                      Comment


                        #12
                        Great thanks. That worked. The form now appears. However, it appears when I single click the strategy when adding the strategy. Then, it appears multiple times when I add the strategy. Is there any way to have it appear only once?

                        Thanks again,

                        Folls

                        Comment


                          #13
                          Make sure you only run the code that creates and shows the form once. You should also take care of closing and disposing of the form.

                          Please see the Dispose() method.

                          RayNinjaTrader Customer Service

                          Comment


                            #14
                            Form1 appears 3 times before strategy is installed

                            I added the following isFormNeeded test to only start it once.

                            public class DLLTest : Strategy
                            {
                            #region Variables
                            // Wizard generated variables
                            private int myInput0 = 1; // Default setting for MyInput0
                            // User defined variables (add any user defined variables below)
                            private bool isFormNeeded = true;
                            #endregion

                            /// <summary>
                            /// This method is used to configure the strategy and is called once before any strategy method is called.
                            /// </summary>
                            protected override void Initialize()
                            {
                            CalculateOnBarClose = true;

                            //added by me to test creating a form from the dll
                            //The "if" was added because multiple forms were begin displayed
                            //This means the Form will only show when the strategy is
                            //installed. Once the form is closed, it won't show up again
                            if (isFormNeeded)
                            {
                            isFormNeeded = false;
                            Form1 dllTest = new Form1();
                            dllTest.Show();
                            }
                            }

                            Now, when I right click on the chart and bring up the strategies window, the Form1 appears 3 times before I even click on it in the strategies window. Then, when I install it, it appears more times. I'm clearly doing something wrong here. Any advice on this?

                            Thanks,

                            Folls

                            Comment


                              #15
                              Move your code to OnBarUpdate() since Initialize() can be called multiple times before its every added to a chart.
                              RayNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by CortexZenUSA, Today, 12:53 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post CortexZenUSA  
                              Started by CortexZenUSA, Today, 12:46 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post CortexZenUSA  
                              Started by usazencortex, Today, 12:43 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post usazencortex  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              168 responses
                              2,266 views
                              0 likes
                              Last Post sidlercom80  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              3 responses
                              13 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X