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

Does Anybody Know How to Program Hot Key in NT?

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

    Does Anybody Know How to Program Hot Key in NT?

    I have an indicator that accumulates data that I wish to reset to zero when certain market conditions occur. I note these conditions visually. Currently I just open the indicator window and click OK, which takes too much time in a fast moving market.

    Does anyone know how I can program a hot key to reset the variable to zero that my indictor uses?

    Thanks,

    Safetrading

    #2
    Hello safetrading,

    There is option of right clicking > reload NinjaScript to reload the indicator. This can also be done with F5 key.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      reply

      Originally posted by NinjaTrader_RyanM View Post
      Hello safetrading,

      There is option of right clicking > reload NinjaScript to reload the indicator. This can also be done with F5 key.
      I tried this, but it does nothing as regards changing the value of the indicator. The indicator only used live data, so every time I load it manually by opening the indicator window and clicking OK, it resets to zero, but when I tried the F5 after folowingthe instructions in the Hot Key help area, it does nothing. Am I missing something?

      Safetrading

      Comment


        #4
        I see. Yeah, it won't reset values of inputs for example. If there were any code changes, these would be reflected after a reload NinjaScript.

        Unfortunately this is outside our scope of NinjaScript support. Hopefully other community members with C# experience can share their input on keypress events.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_RyanM View Post
          I see. Yeah, it won't reset values of inputs for example. If there were any code changes, these would be reflected after a reload NinjaScript.

          Unfortunately this is outside our scope of NinjaScript support. Hopefully other community members with C# experience can share their input on keypress events.
          Thx, I hope so, as the programming seems to be out of my reach.

          Safetrading

          Comment


            #6
            Hi safetrading,

            I was trying to perform the same task. I tried to use RegisterHotKey / UnregisterHotKey with P/Invoke importing user32.dll, but I ran into issues because the only way that seems usable is with a separate form or having access to the NT window message queue because you have to intercept WM_HOTKEY messages. Have you considered adding a button to the chart's toolbar? It is a much more simple approach without the overhead of P/Invoke or overkill of making an entire separate form. I can post what I am currently using if you like

            Comment


              #7
              Originally posted by Dexter View Post
              Hi safetrading,

              I was trying to perform the same task. I tried to use RegisterHotKey / UnregisterHotKey with P/Invoke importing user32.dll, but I ran into issues because the only way that seems usable is with a separate form or having access to the NT window message queue because you have to intercept WM_HOTKEY messages. Have you considered adding a button to the chart's toolbar? It is a much more simple approach without the overhead of P/Invoke or overkill of making an entire separate form. I can post what I am currently using if you like
              Hi Dexter;

              I hadn't thought of what you suggested. Yes, if you don't mind, it would be nice if you would post what you have done with the extra button.

              Thanks,

              Safetrading

              Comment


                #8
                Sure, here are the steps. It will add a simple text button after the properties button on a default chart.

                First, add the forms namespace to your using region
                PHP Code:
                using System.Windows.Forms
                Add some variables in your variables region:
                PHP Code:
                private ToolStrip        toolStrip;
                private 
                ToolStripButton    myButton
                Next in either your Initialize() or OnStartUp() add the logic to find the default toolbar and create your own button
                PHP Code:
                Control[] tsr ChartControl.Controls.Find("tsrTool"false);
                if(
                tsr != null)
                {    
                    
                toolStrip = (ToolStriptsr[0];
                    if(
                toolStrip != null)
                    {
                        
                myButton = new ToolStripButton("Reset");
                        
                myButton.Text "Reset";
                        
                myButton.Click += myButtonClick;
                        
                toolStrip.Items.Add(myButton);
                    }

                You'll need to create an event handler for the button delegate, this is where your desired reset code will go.
                PHP Code:
                private void myButtonClick(object sEventArgs e)
                {
                    
                // do whatever

                Lastly you'll need to remove your button when you remove your indicator. There may be a better way to do this but it works no problem for me so far.
                PHP Code:
                protected override void OnTermination()
                {
                    
                toolStrip.Items.Remove(myButton);
                    
                myButton null;
                    
                base.OnTermination();

                Give that a try and let me know if it works for you

                Comment


                  #9
                  Hi Dexter;

                  Very cool of you to provide such detailed information. I plugged it in ok, and just stuck the sample code below to test it, but with the sample code it would not compile;

                  EnterLongLimit(GetCurrentBid(), "Long Entry Test");

                  Any thoughts on this? I'm not much of a C# coder (obviously). If this is too time consuming for you I understand, and thanks very much for what you have already provided.

                  Safetrading

                  Originally posted by Dexter View Post
                  Sure, here are the steps. It will add a simple text button after the properties button on a default chart.

                  First, add the forms namespace to your using region
                  PHP Code:
                  using System.Windows.Forms
                  Add some variables in your variables region:
                  PHP Code:
                  private ToolStrip        toolStrip;
                  private 
                  ToolStripButton    myButton
                  Next in either your Initialize() or OnStartUp() add the logic to find the default toolbar and create your own button
                  PHP Code:
                  Control[] tsr ChartControl.Controls.Find("tsrTool"false);
                  if(
                  tsr != null)
                  {    
                      
                  toolStrip = (ToolStriptsr[0];
                      if(
                  toolStrip != null)
                      {
                          
                  myButton = new ToolStripButton("Reset");
                          
                  myButton.Text "Reset";
                          
                  myButton.Click += myButtonClick;
                          
                  toolStrip.Items.Add(myButton);
                      }

                  You'll need to create an event handler for the button delegate, this is where your desired reset code will go.
                  PHP Code:
                  private void myButtonClick(object sEventArgs e)
                  {
                      
                  // do whatever

                  Lastly you'll need to remove your button when you remove your indicator. There may be a better way to do this but it works no problem for me so far.
                  PHP Code:
                  protected override void OnTermination()
                  {
                      
                  toolStrip.Items.Remove(myButton);
                      
                  myButton null;
                      
                  base.OnTermination();

                  Give that a try and let me know if it works for you

                  Comment


                    #10
                    Could you paste the compile error you are getting? Also, is this a strategy or indicator? This will be a start for to get all set

                    Comment


                      #11
                      Originally posted by Dexter View Post
                      Could you paste the compile error you are getting? Also, is this a strategy or indicator? This will be a start for to get all set

                      You need to add the following line or it will not compile (failure to override an abstract base function)

                      Code:
                        protected override void OnBarUpdate() {}

                      Comment


                        #12
                        Right, the code posted is what you'd plug into an existing indicator, not an entire one of course

                        safetrading, if you're still having issues could you post the error or listing?

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by PaulMohn, Today, 05:00 AM
                        0 responses
                        7 views
                        0 likes
                        Last Post PaulMohn  
                        Started by ZenCortexAuCost, Today, 04:24 AM
                        0 responses
                        6 views
                        0 likes
                        Last Post ZenCortexAuCost  
                        Started by ZenCortexAuCost, Today, 04:22 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post ZenCortexAuCost  
                        Started by SantoshXX, Today, 03:09 AM
                        0 responses
                        16 views
                        0 likes
                        Last Post SantoshXX  
                        Started by DanielTynera, Today, 01:14 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post DanielTynera  
                        Working...
                        X