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

Problem with hotkeys

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

    Problem with hotkeys

    I have an indicator which is sending orders using the Account method. These orders don't have an ATM strategy.

    I noticed that the hotkeys that reference the "last order", such as "Cancel last order", "Increase last order price", etc, are not working for these orders. These orders are sent with Account.Submit() and are being sent correctly as far as I can tell. They also don't have an ATM strategy and therefore should be included in the definition of "last order" stated in Trading with Hotkeys.

    Other orders sent by ChartTrader in the same chart respond correctly to these "last order" hotkeys. Is there something that I need to set or configure on the order for it to respond to these hotkeys?



    #2
    Hello VolatyTrading,

    Thanks for your post.

    If we look at the Log tab of the Control Center, we can see messages that are relative to the order entry window that the hot key was pressed.
    4/23/2021 6:35:12 AM Order Hot Key Cancel Last Order Chart - There is no order to cancel
    If you are submitting orders with Account.Submit, they would not originate from the NinjaTrader order entry controls and they would not be found when NinjaTrader looks for orders that have originated from that window.

    You would need to create your own hot keys for this sort of functionality. I have attached an example that can subscribe to ChartControl.PreviewKeyDown and ChartControl.PreviewKeyUp where you can detect key presses in your own code.

    Below is a link to another script that I converted in the past that uses a different approach with timers and Regex to detect key presses in a "global" fashion.

    This is a conversion of the a1ChartNotes indicator by monpere. Chart Notes v3 Add notes to your chart. For example, identify a chart template, or put specific notes on how to trade a particular chart, or instrument, etc. – Added selectable fonts and text color – Control Shift toggles compact/expanded visibility (number of lines shown) […]


    The link above is publicly available.

    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.


    We look forward to assisting.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      NinjaTrader_Jim thanks, I was able to detect the OCO order hotkey but not the others related to the "last order". It seems that they are filtered out before reaching my callback.

      Is it possible to use the IOrderEntryHotKeys interface? The interface seems to be straightforward but I would need to register my object somewhere so it can be notified when a hotkey is used. If this is not possible now, can we have a request to make the hotkey interfaces publicly available?

      Comment


        #4
        Hello VolatyTrading,

        There is not any documentation to advise using this in a supported fashion. If you find use interfacing with it and want to inform others of your experience, we would welcome your feedback for what you have tried for the community.

        (Any thing that is not documented NinjaScript is technically unsupported, which just means that we cannot help accomplishing the goal.)

        I have added a vote on your behalf to a feature request tracking interest behind adding this functionality.

        The ticket ID is SFT-2669. This is an internal number, but for anyone else wishing to have their interest tracked, please let our support staff know that you would like a vote added for this request.

        Feature Request Disclaimer

        We receive many requests and cannot reasonably implement all requested features or changes. Interest is tracked internally and if enough interest is tracked, it would be weighed against how feasible it would be to make those changes to consider implementing.

        When new features are implemented, they will be listed in the Release Notes page of the Help Guide. The ID number will be different than the internal feature request tracking ID, but the description of the feature will let you know if that feature has been implemented.

        Release Notes - https://ninjatrader.com/support/help...ease_notes.htm


        We look forward to assisting.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hi Jim,

          thanks for adding my vote to the ticket. In the meantime, I have tried to use the PreviewKeyDown and KeyDown handlers to capture hotkey events, but without much success.

          Apparently only certain hotkey events fire these handlers. For instance, Ctrl+G correctly changes the chart cursor to the "Global" crosshair but it does not fire my event handler. To be more accurate, it does fire the handler but only with the Ctrl key down, not the 'G' key:

          Code:
          Modifiers: Control
          Key.System: System
          e.Key: LeftCtrl
          e.SystemKey: None
          e.KeyStates: Down
          e.ImeProcessedKey: None

          I assume that the Ctrl+G event is being handled before reaching my handler, and e.Handled is being set to true at that time.

          Any idea how can I capture these missing hotkey events?
          Last edited by VolatyTrading; 05-17-2021, 03:01 PM.

          Comment


            #6
            Hello VolatyTrading,

            The tips I have given in post #2 would be my only unsupported ideas for being able to handle the key presses. I do see that the PreviewKey approach would not work for already handled hot keys and using Regex as is done in ChartNotes may not be suitable for non-modifier keys.

            Since we are talking about doing things that are not documented/supported, I do not have any additional insight I can offer.

            I would then suggest using different key combinations for your AddOn. Otherwise another community member may have some input for handling key presses which are already owned by NinjaTrader hotkeys.

            We look forward to assisting.
            JimNinjaTrader Customer Service

            Comment


              #7

              Ninja processing handles many if not most keystrokes and PreviewKey never gets called.

              Below is code that intercepts all messages that are sent to a window. In those messages are contained the keystroke messages which can be trapped and acted upon.

              To get started message 257 is the WM_KEYUP message and wParam contains the key which was pressed. 33=Page up 34=Page down 113 is F2 and so on...


              For a list of windows message numbers see https://wiki.winehq.org/List_Of_Windows_Messages
              Credit where credit is due: https://stackoverflow.com/questions/624367


              Code:
              using System.Windows.Interop;
              
              private Window chartWindow;
              private HwndSourceHook HwndHook;
              private HwndSource SourceWindow;
              
              //Get windows messages
              chartWindow = System.Windows.Window.GetWindow(ChartControl.Paren t) as Window;
              SourceWindow = HwndSource.FromHwnd(new WindowInteropHelper(chartWindow).Handle);
              HwndHook = new HwndSourceHook(WndProc);
              SourceWindow.AddHook(HwndHook);
              
              
              private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
              {[INDENT]Print(msg +_+ wParam);
              
              [/INDENT][INDENT]if (msg==257)
              {[/INDENT][INDENT=2]string Ky="";
              int KeyCode=(int)wParam;
              if (KeyCode==33) Ky="Up";
              else if (KeyCode==34) Ky="Down";
              else if (KeyCode==113) Ky="F2";
              else return IntPtr.Zero;[/INDENT][INDENT]}
              
              return IntPtr.Zero;[/INDENT]
               }

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Skifree, Today, 03:41 AM
              1 response
              2 views
              0 likes
              Last Post Skifree
              by Skifree
               
              Started by usazencort, Today, 01:16 AM
              0 responses
              1 view
              0 likes
              Last Post usazencort  
              Started by kaywai, 09-01-2023, 08:44 PM
              5 responses
              603 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              6 responses
              23 views
              0 likes
              Last Post xiinteractive  
              Started by Pattontje, Yesterday, 02:10 PM
              2 responses
              23 views
              0 likes
              Last Post Pattontje  
              Working...
              X