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

    #16
    Thanks. I moved the code to onbarupdate. I still get three Form1's as follows.

    1) When I right click on chart and bring up the strategies window, a Form with no button appears.
    2) When I apply the strategy to the chart, a form with a button appears.
    3) When I click OK in the strategies window, the final form with a button appears.

    I think we're getting closer. Any more advice?

    Folls

    Comment


      #17
      Unfortunately not, looks like you will need to roll up your sleeves and debug this.
      RayNinjaTrader Customer Service

      Comment


        #18
        Just to sum up what I wrote to Folls in a PM, so that others may benefit as well.

        First of all, I believe the blank form is being shown from one of your strategies where you were experimenting with forms. Initialize will get called once on all compiled strategies as soon as you open the strategies window, so it could easily be another of your strategies causing this.

        Whenever you click "Apply" or "OK" in the strategies window all currently running strategies on the chart are stopped and new instances of them are created.

        This means that any variables inside the strategies will be reset. Creating a property around the variable seems to allow values to be carried over between instances.

        However, once you move your code to OnBarUpdate it means that your strategy will processing all your historical data as well as any incoming realtime data while you have the window open using whatever default settings the strategy has.

        Any settings you change after the strategy has been started will not be applied retroactively unless you reload the strategy.

        It would be really cool if there was something like a BeforeFirstBarUpdate method where we could execute custom initialization code only once before any bar updates are processed.
        Last edited by gert74; 09-23-2007, 09:45 PM.

        Comment


          #19
          Thanks very much! I get one Form now.

          Thanks! That worked great. I now get only one form. I'll make a simple Visual Studio application that exchanges data with Ninja Trader via a form. I'll then post the Visual Studio project, the Ninja strategy code, and a brief document describing what I did.

          That will hopefully help others that are interested in passing values to and from Ninja.

          Folls

          Comment


            #20
            handle event fired from the form

            I'm still working on my basic example. I have one that appears to be working where I check in OnBarUpdate() to see if the input to the form has changed. However, it would be better if the notification of changed input was event driven. So, I put the following in the Visual Studio code to fire an event when the Input button is clicked:

            //event to notify ninja that enter has been clicked with new input
            public event EventHandler InputAlert;

            private void button1_Click(object sender, EventArgs e)
            {
            //if there is input
            if (String.Compare(textBox1.Text, "") > 0)
            {
            InputValue1 = Convert.ToDouble(textBox1.Text);
            InputValue2 = Convert.ToDouble(textBox2.Text);

            textBox3.Text = (InputValue1 * InputValue2).ToString();

            //notify ninja new input has been entered by firing an event
            if (InputAlert != null)
            InputAlert(this, new EventArgs());
            }
            }

            Now, when I try to create an event handler and register it in the strategy, it won't compile. I have the following code in the OnBarUpdate() method. I have also tried it in Initialize() with the same result. Both times I get the error "statement expected".

            //an event is fired when new input is entered
            //create an event handler and register it
            private void InputAlertHandler(object sender, EventArgs e)
            {
            //get the new info, multiply, store, and display in the form
            inputOutputForm.OutputValue1 = inputOutputForm.inputValue1 * inputOutputForm.inputValue1;
            inputOutputForm.Controls["textBox4"].Text = (inputOutputForm.inputValue1 * inputOutputForm.inputValue1).ToString();

            }
            inputOutputForm.InputAlert += new EventHandler(InputAlertHandler);

            Do you have any advice on how to get this to compile with the event handler and registration?

            Thanks!

            Folls

            Comment


              #21
              I do not know if this is your problem, but I can see an inconsistency with the input value properties on the form.

              In your form code you use InputValue1 and InputValue2 with captial I while in you strategy code you use lower case i.

              Usually the compile error messages at the bottom of the code editor will give you some good info on what is wrong and if you double click the error message it will take you to the line of code that is causing problems.

              Comment


                #22
                Thanks! That was definitely a problem that would have surfaced if I can get past this one. I included a picture of what is happening with line numbers and error messages. I can comment out all code (as shown in the picture) in the method as well as the register code and still have the same problem. If I remove the InputAlertHandler method entirely, it compiles. If I put the InputAlertHandler method in Visual Studio, there is no error.

                For some reason, Ninja doesn't like it. Am I allowed to have this method in the OnBarUpdate() or Initialize()? I get the same problem when InputAlertHandler is in either method. I don't believe there is anywhere else to put it.

                Any more help would be appreciated!

                Folls
                Attached Files

                Comment


                  #23
                  OK, now I see the problem.

                  You cannot define a method inside another method.

                  Just move your InputHandler method outside the OnBarUpdate method and you should be alright.

                  Comment


                    #24
                    Example of simple Windows Form from Visual Studio

                    Thanks for the help! Here is a simple example of a Form made in Visual Studio and then used in a Ninja Strategy.

                    Read the text file. It explains how to install the example.

                    I wouldn't recommend attempting this idea unless you have some programming experience.

                    I hope it helps someone!

                    Folls
                    Attached Files

                    Comment


                      #25
                      Thank You Folls!

                      just a quick not to say this is by far the most useful example I have seen so far.

                      Comment


                        #26
                        button click

                        Thank you for this. Using this and some other samples I was able to create a form from inside the OnBarUpdate. I'm now trying to place command buttons directly on the chart page, but just can not get it right. Anyone have any suggestions? Thanks, Ken

                        Comment


                          #27
                          Nice to have someone explain stuff so clearly

                          Thanks Folls, this is going to be most helpful with an indicator that I am developing.

                          Comment


                            #28
                            Hello,

                            Is it possible to create buttons on the chart directly to allow the user interact with a script/strategy instead of creating a form window outside of the chart? Is there anyone already did this? Help is appreciated.

                            - Clearpicks

                            Comment


                              #29
                              clearpicks,

                              Unfortunately this is beyond the level of what we can support, but hopefully some of the more advanced users who may have done so can help you out.
                              Josh P.NinjaTrader Customer Service

                              Comment


                                #30
                                I think you would need a routine to first get the window handle ...

                                There is some good code here to help give you an idea of how to get the NT window handles. You will also need an Object Spy of somekind to get the form names, etc. I think.



                                Originally posted by clearpicks View Post
                                Hello,

                                Is it possible to create buttons on the chart directly to allow the user interact with a script/strategy instead of creating a form window outside of the chart? Is there anyone already did this? Help is appreciated.

                                - Clearpicks

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by kaywai, Today, 06:26 AM
                                1 response
                                6 views
                                0 likes
                                Last Post kaywai
                                by kaywai
                                 
                                Started by ct, 05-07-2023, 12:31 PM
                                6 responses
                                205 views
                                0 likes
                                Last Post wisconsinpat  
                                Started by kevinenergy, 02-17-2023, 12:42 PM
                                118 responses
                                2,780 views
                                1 like
                                Last Post kevinenergy  
                                Started by briansaul, Today, 05:31 AM
                                0 responses
                                10 views
                                0 likes
                                Last Post briansaul  
                                Started by traderqz, Yesterday, 12:06 AM
                                11 responses
                                28 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Working...
                                X