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

Keys Listener Selector

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

    Keys Listener Selector

    I'm trying to add a Keys Listener/selector to let one chose the key from the Indicator Properties Preferences window to go with a Hotkey.

    I thought of using some enums but it seems the very tedious way to do it though simple:

    if (Keyboard.IsKeyDown(Key.hotkeyOne))
    {
    //DoX;
    }


    switch (HotkeysSel)
    {

    case CustomEnumNamespacex.HotkeysSelectorx.A_Letter:
    {
    hotkeyOne = "NumPad9";
    break;
    }
    case CustomEnumNamespacex.HotkeysSelectorx.B_Letter:
    {
    hotkeyOne = "NumPad9";
    break;
    }

    etc. for all keys... then multiplied by the number of hotkeys.

    What better way is there available with NT8? Isn't there a hotkeys selector available (like those Nuget Packages)

    If not what more direct way would you suggest to do it? Thanks!

    #2
    Hi Paul, It depends on what you want to do with the key down event. NinjaTrader already supports hotkeys where you can do a number of things:



    We also have an example here demonstrating prreviewkeydown events:



    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hello Chris and thanks for the examples. I see there is a Hotkeys assigner already built-in.
      I'd like the same but to use/call in the Indicator Properties Preference windows on the chart (Ctrl+I). The end use would be to allow for selecting a hotkey when the user presses the corresponding key/Keys combination in the Keys listener field (something like this HotkeyListener gif from here).

      Once selected, the hotkey would simply set the string content of the KeyDown Event in the script as

      if (Keyboard.IsKeyDown(Key.hotkeyOne))
      {
      //CreateOrder(BuyMktOrder...);
      }

      Where hotkeyOne would be the variable picking the Key string from the hotkey listener.

      For example:
      1. the user focuses his mouse cursor in the Hotkey Listener field in the Indicator Properties Preference windows
      2. then the user presses whatever key/key combination of his choice
      3. the Hotkey listener picks it up and saves it in the variable hotkeyOne
      4. finally when the user presses the given key/keys combination
      5. the KeyDown Event executes.

      Illustration:
      1. User focuses the cursor in Hotkey Listener Field
      2. User inputs "Ctrl+O"
      3. Hotkey Listener assigns "Ctrl+O" to variable hotkeyOne
      4. User presses "Ctrl+O" on the Chart
      5. NT8 submits BukMkt Order
      The strings assignment seems straightforward but could be very laborious to implement one by one (1000+ statements for just 10 Hotkeys if we take all keys).

      Do you know/can think of a better way? Possibly a way that also handle/ignores the reserved NT8 keys/keys combinations? Thanks!
      Last edited by PaulMohn; 05-19-2022, 12:40 PM.

      Comment


        #4
        Hi Paul, Im not aware of any way to do this. I apologize but any C# or hotkey modification goes outside of the scope of support I am able to provide. If it is not in the help guide, the support team will generally not be able to assist any further in it. This thread will remain open indefinitely for other members of the forum to contribute.

        Kind regards,
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chris. I've found some more lead but not straightforward.
          Just to be sure, there isn't a way as now to call your built-in Hotkeys assigner to populate it as input filed in the indicator Properties Preference window (just to be sure so I don't look for some alternative if it's already available)? Something like the QuantitySelector Control (which we can call in the Toolbar for user input) ? Otherwise could the team in charge of the Hotkeys assigner code consider providing a new feature/a function we could call? Else we're reduced to using complicated enums/lenghty enums or a nuget package. Thanks!

          Also do you know where to find the reserved NT8 Keys list? Thanks!
          Last edited by PaulMohn; 05-19-2022, 01:08 PM.

          Comment


            #6
            Hi Paul, thanks for your reply. The hotkey module is not available to the scripting library. There is an existing feature request to add a hotkey menu as a property/WPF control ID# SFT-3900. I added a vote to it for you.

            Kind regards,
            -ChrisL
            Last edited by NinjaTrader_ChrisL; 05-19-2022, 02:22 PM.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Global Shortcuts in WinForms and WPF

              Library that allows an app to process hotkeys and perform other keyboard manipulations


              reference for later tests.

              Comment


                #8
                Hi Paul
                Very nice piece of work.
                For consideration:
                1. Limit orders rather than entry at market - via a mouse click - my own code version is here. My only issue with my code is it's a little "sticky" - sometimes I have to hit the Ctrl+mouse click 2 or even 3 times to get the order on. I think that maybe because I am using preview Key down rather than key down
                2. Select the account like you have the QS - that would be really nice. I know it would take up a lot of real estate in the toolbar but it's something I would actually use.

                Finally - does the code really need to run on each tick as it's mostly event-driven? - just enquiring if there is any way to suck up less resources.

                anyway Kudos for sharing and some great work.

                Comment


                  #9
                  Hi Mindset and thanks for your input and questions.

                  1. Yes limit orders as replacement to market orders is simple to do.


                  you would need to change
                  OrderType.Market,

                  to

                  OrderType.Limit,

                  in

                  PHP Code:
                  entryBuyMar****rder   myAccount.CreateOrder(
                        
                  Instrument,
                        
                  OrderAction.Buy,
                        
                  OrderType.Market,
                        
                  OrderEntry.Manual,
                        
                  TimeInForce.Day,
                        
                  quantitySelector.Value,
                        
                  0,
                        
                  0,
                        
                  string.Empty,
                        
                  "Entry",
                        
                  Core.Globals.MaxDate,
                        
                  null);


                  ------------------------

                  entrySellMar****rder   myAccount.CreateOrder(
                        
                  Instrument,
                        
                  OrderAction.Sell,
                        
                  OrderType.Market,
                        
                  OrderEntry.Manual,
                        
                  TimeInForce.Day,
                        
                  quantitySelector.Value,
                        
                  0,
                        
                  0,
                        
                  string.Empty,
                        
                  "Entry",
                        
                  Core.Globals.MaxDate,
                        
                  null); 
                  And also determine how many ticks from the GetCurrentBid() / GetCurrentAsk()
                  to set the limit price at.

                  2. You'd like an account Selector dropdown in the toolbar? To be able to flip account on the fly directly from the Toolbar?
                  The current account Selector is available from the Chart Properties (Ctrl+I with focus on the chart). It was Jim's use.
                  I don't think there's a Ninjatrader custom dropdown 'module' available for the ToolBar like there is for the QS shared by Jesse.
                  If there's not, that means we would need to code it from scratch, if it is even possible, with all the NT "backend" commands references (undocumented and possibly available via Visual Studio).
                  Multiple accounts "settings" restrictions also depend on brokers policies, for example Interactive Brokers allow multiple accounts, but I'm not sure you can "hedge"/go both Long and Short on the same instrument at the same time on different accounts. Other brokers don't.
                  Also, you could use multiple charts and load the indicator on each with preselected different accounts on each chart (keeping in mind the Hedging restrictions from your broker).
                  Since traders typically do not change account regularly that might be a good enough alternative.

                  3. Yes this version should work as well with OnBarClose instead of OnEachTick. I used on each tick on another version having to call the OnBarUpdate loop with Position == null checks.

                  Thanks again for the ideas. I'll test those asa (I have got other features down the pipeline coming).

                  Also, I think Ninjatrader User Apps Share Service is defective somehow and waiting for some fix as they've not been able to update scripts for some time.
                  You can find a new version of ProfitSniper in this other post in the User Apps Share service fix intervall.

                  Latest version
                  https://ninjatrader.com/support/foru...19#post1206419

                  Previous version
                  https://ninjatrader.com/support/foru...ix#post1206413
                  Last edited by PaulMohn; 07-07-2022, 04:28 AM.

                  Comment


                    #10
                    Thanks Paul. Appreciate the response.
                    FYI NT have updated the Ecosystem so your latest version 2 is up there.

                    On the Account selector idea - yes I feel it's not worth the time and resources - just would be nice. I was kind of hoping someone had done the QS idea for Accounts and might throw it in!!

                    Comment


                      #11
                      Perhaps the NinjaScript Account Selector control is what you are looking for: https://ninjatrader.com/support/help...ntselector.htm

                      Thanks.
                      Multi-Dimensional Managed Trading
                      jeronymite
                      NinjaTrader Ecosystem Vendor - Mizpah Software

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by bmartz, 03-12-2024, 06:12 AM
                      4 responses
                      31 views
                      0 likes
                      Last Post bmartz
                      by bmartz
                       
                      Started by Aviram Y, Today, 05:29 AM
                      4 responses
                      12 views
                      0 likes
                      Last Post Aviram Y  
                      Started by algospoke, 04-17-2024, 06:40 PM
                      3 responses
                      28 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by gentlebenthebear, Today, 01:30 AM
                      1 response
                      8 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by cls71, Today, 04:45 AM
                      1 response
                      7 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Working...
                      X