Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Hotkey's for Trading Keyboard - completed AHK code
Hopefully this is the correct place to post this - Please move if not appropriate.
I have been looking for a solution for awhile to send the same order to multiple platforms (Sierra Charts LIVE, Sierra Charts SIM, NT8 SIM). I've switched all live trading over to Sierra Charts and most of the charting but have had to still use NT for Jigsaw. This caused a bit of a issue with not being able to see active orders on the Jigsaw DOM and I ended up having to try watch 2 separate screens when in a trade and this became a issue when I needed to closely watch the Jigsaw DOM as I would sometimes loose track of price levels.
So the solution was to setup hotkeys that would send the same command to each platform with the ability to turn off/on the commands to the Sierra Charts LIVE platform as needed on the fly.
Here is the working code that I have come up with using AutoHotKey (https://autohotkey.com/)
Please excuse any mistakes or lack of proper coding etiquette, this is the 1st thing I've put together. Any feedback, pointers or better ways would be greatly appreciated. (A big thanks has to go to a mate who sat down and explained what Variables are and how to capture them for the session.)
After all 3 platforms are running, launch complied AHK program.
; --------- Click on and make active charts on platform 1 then use the hotkey - Ctrl + R
^R::
WinGet, WinID, ID, A ; --------- This finds and stores the variable Window ID for that platform for that session.
WinID_ctrl_R= ahk_id %WinID%
WinActivate, %WinID_ctrl_R% ; --------- This is the stored variable Window ID for that platform for that session that can then be called on later.
Return
; ---------- Click on and make active charts on platform 2 then use the hotkey - Ctrl + Y
^Y::
WinGet, WinID, ID, A ; --------- This finds and stores the variable Window ID for that platform for that session.
WinID_ctrl_Y= ahk_id %WinID%
WinActivate, %WinID_ctrl_Y% ; --------- This is the stored variable Window ID for that platform for that session that can then be called on later.
Return
; Click on and make active charts on platform 3 then use the hotkey - Ctrl + Q
^Q::
WinGet, WinID, ID, A ; --------- This finds and stores the variable Window ID for that platform for that session.
WinID_ctrl_Q= ahk_id %WinID%
WinActivate, %WinID_ctrl_Q% ; --------- This is the stored variable Window ID for that platform for that session that can then be called on later.
Return
#If GetKeyState("ScrollLock", "T") ; --------- This sets up "Scroll lock" key as a toggle - On = send command, Off = Don't send command. Only what is inside the #If statements are affected.
^Z:: ; ---------------------------------------------- Hotkey Ctrl + Z (Hotkey is only pressed once but depending on "Scroll Lock" toggle position, it will be sent to LIVE platform or not).
WinActivate, %WinID_ctrl_R% ; -------------- This references Platform 1 session WinID
Send, {LAlt Down}{s}{LAlt Up} ; ------------ Platform trade hotkey Alt + S
#If ; ------------------------------------------------ Closes #If statement
^Z:: ; ---------------------------------------------- Hotkey Ctrl + Z (This hotkey command gets sent always and will activate 2 platforms)
WinActivate, %WinID_ctrl_Y% ; -------------- This references Platform 2 session WinID
Send, {LAlt Down}{a}{LAlt Up} ; ------------ Platform trade hotkey Alt + A
WinActivate, %WinID_ctrl_Q% ; -------------- This references Platform 3 session WinID
Send, {LAlt Down}{j}{LAlt Up} ; ------------ Platform trade hotkey Alt + J
Return ; ---------------------------------------------- Reset
#If GetKeyState("ScrollLock", "T") ; --------- This sets up "Scroll lock" key as a toggle - On = send command, Off = Don't send command. Only what is inside the #If statements are affected.
^A:: ; ---------------------------------------------- Hotkey Ctrl + Z
WinActivate, %WinID_ctrl_R% ; -------------- This references Platform 1 session WinID
Send, {LAlt Down}{t}{LAlt Up} ; ------------ Platform trade hotkey Alt + T
#If ; ------------------------------------------------ Closes #If statement
^A:: ; ---------------------------------------------- Hotkey Ctrl + Z
WinActivate, %WinID_ctrl_Y% ; -------------- This references Platform 2 session WinID
Send, {LAlt Down}{b}{LAlt Up} ; ------------ Platform trade hotkey Alt + B
WinActivate, %WinID_ctrl_Q% ; -------------- This references Platform 3 session WinID
Send, {LAlt Down}{k}{LAlt Up} ; ------------ Platform trade hotkey Alt + K
Return ; ---------------------------------------------- Reset
; (This same process is repeated through each set until the last 2 which are slightly different)
; (These following 2 are only relevant to Sierra Charts because NT doesn't support the function currently. Ask NT to include this function in future releases as its great to use)
; This is for the "Stop Order Tick Up" and "Stop Order Tick Down" hotkeys avalible in Sierra Charts.
#If GetKeyState("ScrollLock", "T") ; --------- This sets up "Scroll lock" key as a toggle - On = send command, Off = Don't send command. Only what is inside the #If statements are affected.
^V:: ; ---------------------------------------------- Hotkey Ctrl + V
WinActivate, %WinID_ctrl_R% ; -------------- This references Platform 1 session WinID
Send, {LAlt Down}{z}{LAlt Up} ; ------------ Platform trade hotkey Alt + Z
#If ; ------------------------------------------------ Closes #If statement
^V:: ; ---------------------------------------------- Hotkey Ctrl + V
WinActivate, %WinID_ctrl_Q% ; -------------- This references Platform 3 session WinID
Send, {LAlt Down}{q}{LAlt Up} ; ------------ Platform trade hotkey Alt + Q
Return ; ---------------------------------------------- Reset
See attached "Hotkeys_3_Platforms_A.txt" for full code. This needs to be saved as a .ahk file before it can be complied. Open file in Notepad>save as>(Save as type: All files)> yourfilename.ahk>Save.
Must have AutoHotKey installed> right mouse click yourfilename.ahk> Compile Script
It will then produce the autohotkey application and when its needed> right mouse click> Open
It will stay running in the task manager background processes for the computer session or until you manually kill it in Windows Task Manager.
The Sierra Charts LIVE platform was positioned 1st in line, followed by NT SIM with the Jigsaw DOM as this is the order of importance I needed when live trading and to cut down on slippage due to delayed execution when 3 commands are sent one after the other. I have noticed some small differences of 1 tick occasionally on the 3rd platform but I'm not really using it to live trade, its just the fall back sim trade so it doesn't cause any real issue for me.
The above AHK program will then make each platform "window" active when needed. If you manually switch charts (Child Tab) on all 3 platforms and bring a new instrument to the forefront EG- ES to ZB, the hotkeys will then work on those charts.
NOTE: You MUST activate "Trading Keyboard Short Cuts Enabled" on EACH chart you need in Sierra charts. When each chart is at the forefront in Sierra Charts> Trade> Trading Keyboard Short Cuts Enabled. It will then allow Hotkeys to be used on this chart when its at the forefront of the parent window and will only use hotkeys on that chart while its at the forefront "active". (I think you need to enable "Chart Trade Mode" and(??) "Attach Trade Window to Chart"on each chart the hotkeys will be used on.)
Nt doesn't need each chart enabled, it has a global setting. Tools> Options> Trading> Use Order Entry hot keys. It will then allow Hotkeys to be used on this chart when its at the forefront of the parent window and will only use hotkeys on that chart while its at the forefront "active". (I think you need to enable "Chart Trader" on each chart the hotkeys will be used on.)
I kept Alt + "*" for the hotkeys to be set inside each platform and have attached a spreadsheet with the legend I used for each platform. These must be manually set in each platforms hotkey settings. Alternatively, you can change the code to suit your own platform hotkey bindings. In the code, I used all lower case for the platform hotkey alphabetic keys but on the legend I used uppercase so that they clearly show what letters are used.
I used Ctrl + "*" for the hotkeys for AHK.
This then allowed "Shift" to still be used normally for typing on the keyboard and not accidentally fire off a hotkey that triggers a order somewhere.
My next thing to tackle is to setup and use the 5 keys in the upper left of the "Trading Keyboard Hotkeys.PNG" to somehow bind them to individual child tabs in each trading platform window so that 1 key will bring all 3 platforms ES charts to the forefront, another will bring all 3 platforms 30yr US Treasuries ZB charts to the forefront and so on.
Seeming to run into some major issues with doing this as AutoHotKey doesn't like finding child tabs, making them active and bringing them to the forefront inside the parent window. There are ways around it by using known x, y screen positions and auto-mouse clicking the tabs but this would mean everything needs to stay in the same relative screen positions all the time with nothing obstructing the mouse click target which is not ideal. The other option is to search for a image of the tab name but this is slow and prone to issues from what I have read.
If anyone knows how to do this using AutoHotkey or even a completely different language/way, it would be great to hear some options to look into.
Please give feedback on where I can improve, this is my 1st effort and its taken a bit to get my head around.