Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting data from console

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

    Getting data from console

    Hi
    I would like to get data from keyboard, when a script is running. There is a special method for this (waiting characters from keyboard, and read it) or I have to use the native C# commands, like Read, ReadLine.
    It is very improtant for me, because I want to give parameters (stop, size, profit...) directly when the script is running, and the scipt wait for data before a decision.

    Thank You in advance...


    Best regards

    Akos

    #2
    Hello Akos,

    Thank you for your post.

    This would be unsupported, however, below you will find code from an indicator to print to the Output window when the key 'A' is pressed on the keyboard.
    Code:
                private int myInput0 = 1; 
    			private Form myWindow;
    			private Panel panel;
    			private EventInfo ei;
    			private Delegate d;
    		
            #endregion
    		
            protected override void Initialize() 
    		{
    			Overlay				= true;
    			CalculateOnBarClose = true;
            }
    		
    		protected override void OnStartUp()
    		{
    			myWindow = (Form)ChartControl.Parent;
    			panel = (Panel)myWindow.Controls.Find("pnlChart", true).FirstOrDefault();
    			
    			ei = panel.GetType().GetEvent("PreviewKeyDown");
    			d = Delegate.CreateDelegate(typeof(PreviewKeyDownEventHandler), ChartControl, "OnKeyPreview", true);
    			ei.RemoveEventHandler(panel, d);
    			
    			panel.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.KeyPress1);			
    		}
    		
            protected override void OnBarUpdate()
            {
    			
    		}
    		
    		void KeyPress1(object sender, PreviewKeyDownEventArgs e)
    		{
    			if(e.KeyCode == Keys.A)
    			{
    				Print("working");
    			}
    		}
    		
    		protected override void OnTermination()
    		{
    			//panel.PreviewKeyDown -= new PreviewKeyDownEventHandler(KeyPress1);
    			//panel = null;
    			myWindow.PreviewKeyDown -= new System.Windows.Forms.PreviewKeyDownEventHandler(this.KeyPress1);
    			myWindow = null;
    
    			ei.AddEventHandler(panel, d);
    		}

    Comment


      #3
      Hello Patrick
      Thank You for your answer
      It is more complicated, then I expected. It means, that the C# commands are not usable?
      About the code:
      The KeyPress1 is the method, for waiting and getting the push? How does it works? Where is the definition of the parameters? I would impressed if You wrote about is some words.

      May be, that it is better to test or backtest a strategy on historical data, when I can play the strategy, and on the appropriate time I make the orders, and I give the parameters of the orders?

      Best regards Akos

      Comment


        #4
        Hello Akos,

        Thank you for your response.

        The code is actually C# code, but it is unsupported in NinjaScript.

        The void KeyPress1() would be the method that is called when the key is pressed, it is checking what key was pressed.

        I can provide some insight here on the functions but please let me know what you would like information on.

        Comment


          #5
          getting data from console or keyboard

          Hello Patrick,
          I have the same or similar task.
          While strategy is running I want to read a single character from keyboard. Like "HotKey", but with special function:
          (1) Activate or
          (2) deactivate strategy
          (3) Up or
          (4) down of StopLoss
          (5) Up or
          (6) down of TakeProfit.

          The keyboard input is ONE character only, can also be alphabetical, so an easy way would be nice.

          Comment


            #6
            Hello optimalTrading,

            Thank you for your post and welcome to the NinjaTrader Support Forum!

            Is this a strategy you are building? Have you tested out the example in this thread? And are you looking for the appropriate functions to call for each number in your inquiry?

            I look forward to your response.

            Comment


              #7
              Getting data from console

              Hello Patrick,
              strategy is ready, running fully automatic. But this point is missing.
              I will test the example next week, if no easier way is availible.

              Inside my strategy all of the mentioned parameters are used. They are now defined automatically, depending on the situation in the market. To adapt it manual I need an "input" either from keyboard or any other "source".
              It might also be of interest to open, change and save a .txt file manually and to read it automatically. The content might be for example A, 15325, 15396 for the parameters = Active or Deactivated, StopLoss, TakeProfit. Comma as a separator.
              Do you think this might be easier?
              If NT does not support full C#, how should this be programmed?
              Thank you for your ideas or hints.

              Comment


                #8
                Hello optimalTrading,

                Thank you for your response.

                The example provides detail on using a keyboard stroke to fire off an action. General C# is not supported by our support team, however it is still possible to implement C# concepts into NinjaScript as it is based on C#.

                The example is available at the following link: http://ninjatrader.com/support/forum...89&postcount=2

                Please let me know if you have any questions.

                Comment


                  #9
                  Getting data from console

                  Hello Patrick,
                  thank you. I tried to implement, but there are error messages.
                  My qeustions:
                  1 - private int myInput0 = 1; was included in the definition of variables. No problem.
                  2 - private Form, private Panel, private EventIno and private Delegate seem to be classes. Including into the "using declarations" the line "using System.Windows.Forms" eliminates errors for "Panel". But the other definitions create errors. I assume that they are classes, but do not know where to create new classes. Pls explain.
                  3 - Including "Overlay = true;" does not work. Overlay seems not to be defined.
                  4 - All other text parts are included at the correct position, but can not be tested without clarification of point 2.

                  Seems to be my missing knowledge of C#.

                  Thank you for your assistance.

                  Comment


                    #10
                    Hello optimalTrading,

                    Thank you for your response.

                    I assume based on your response you are using NinjaTrader 8 and not NinjaTrader 7 for this project.

                    SendKeys will not work in NinjaTrader 8. This functionality has been requested and assigned the id SFT-1085. I will add a vote for this feature.

                    Please let me know if you have any questions.

                    Comment


                      #11
                      Hello Patrick,
                      I use NT 7.
                      I now implemented the following two new lines in the #region Using declarations:
                      using System.Windows.Forms;
                      using System.Reflection;

                      The only error which now is coming is because of line
                      panel = (Panel)myWindow.Controls.Find("pnlChart", true).FirstOrDefault();
                      The error message is (translated from German to English by me): "System.Array" contains no definition for "FirstOrDefault" and there could not be found a method for "FirstOrDefault" which accepts a first argument for "System.Array". May be a using directive is missing.

                      Hope this will help you.
                      Thank you again for your help.

                      Comment


                        #12
                        Hello optimalTrading,

                        Thank you for your response.

                        This would be outside the scope of our support here. Such items would be unsupported in NinjaScript.

                        Please let me know if you have any questions.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by fx.practic, 10-15-2013, 12:53 AM
                        5 responses
                        5,403 views
                        0 likes
                        Last Post Bidder
                        by Bidder
                         
                        Started by Shai Samuel, 07-02-2022, 02:46 PM
                        4 responses
                        94 views
                        0 likes
                        Last Post Bidder
                        by Bidder
                         
                        Started by DJ888, Yesterday, 10:57 PM
                        0 responses
                        6 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Started by MacDad, 02-25-2024, 11:48 PM
                        7 responses
                        158 views
                        0 likes
                        Last Post loganjarosz123  
                        Started by Belfortbucks, Yesterday, 09:29 PM
                        0 responses
                        8 views
                        0 likes
                        Last Post Belfortbucks  
                        Working...
                        X