NexusFi: Find Your Edge


Home Menu

 





Hotkey's for Trading Keyboard - completed AHK code


Discussion in Sierra Chart

Updated
    1. trending_up 2,539 views
    2. thumb_up 3 thanks given
    3. group 2 followers
    1. forum 0 posts
    2. attach_file 3 attachments




 
Search this Thread

Hotkey's for Trading Keyboard - completed AHK code

  #1 (permalink)
 SilverFut 
Brisbane + Queensland/Australia
 
Experience: Beginner
Platform: NinjaTrader, Sierra Chart
Broker: CQG, IQFeed
Trading: S&P Emini Futures
Posts: 54 since Mar 2015
Thanks Given: 38
Thanks Received: 89

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)

#If GetKeyState("ScrollLock", "T")
^X::
WinActivate, %WinID_ctrl_R%
Send, {LAlt Down}{u}{LAlt Up}
#If
^X::
WinActivate, %WinID_ctrl_Y%
Send, {LAlt Down}{c}{LAlt Up}
WinActivate, %WinID_ctrl_Q%
Send, {LAlt Down}{l}{LAlt Up}
Return

#If GetKeyState("ScrollLock", "T")
^S::
WinActivate, %WinID_ctrl_R%
Send, {LAlt Down}{v}{LAlt Up}
#If
^S::
WinActivate, %WinID_ctrl_Y%
Send, {LAlt Down}{d}{LAlt Up}
WinActivate, %WinID_ctrl_Q%
Send, {LAlt Down}{m}{LAlt Up}
Return

#If GetKeyState("ScrollLock", "T")
^C::
WinActivate, %WinID_ctrl_R%
Send, {LAlt Down}{w}{LAlt Up}
#If
^C::
WinActivate, %WinID_ctrl_Y%
Send, {LAlt Down}{e}{LAlt Up}
WinActivate, %WinID_ctrl_Q%
Send, {LAlt Down}{n}{LAlt Up}
Return

#If GetKeyState("ScrollLock", "T")
^D::
WinActivate, %WinID_ctrl_R%
Send, {LAlt Down}{x}{LAlt Up}
#If
^D::
WinActivate, %WinID_ctrl_Y%
Send, {LAlt Down}{f}{LAlt Up}
WinActivate, %WinID_ctrl_Q%
Send, {LAlt Down}{o}{LAlt Up}
Return

#If GetKeyState("ScrollLock", "T")
^B::
WinActivate, %WinID_ctrl_R%
Send, {LAlt Down}{y}{LAlt Up}
#If
^B::
WinActivate, %WinID_ctrl_Y%
Send, {LAlt Down}{g}{LAlt Up}
WinActivate, %WinID_ctrl_Q%
Send, {LAlt Down}{p}{LAlt Up}
Return


; (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

#If GetKeyState("ScrollLock", "T")
^F::
WinActivate, %WinID_ctrl_R%
Send, {LAlt Down}{1}{LAlt Up}
#If
^F::
WinActivate, %WinID_ctrl_Q%
Send, {LAlt Down}{r}{LAlt Up}
Return


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.

I setup a custom Trading keyboard from Trading Keyboard | Sample Configurations | Keyboard Trader. It is a access-IS 15 x 8 base. See layout picture




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.

I hope this can help someone else in some way.

Attached Thumbnails
Click image for larger version

Name:	Trading Keyboard Hotkeys.PNG
Views:	372
Size:	34.9 KB
ID:	217703  
Attached Files
Elite Membership required to download: MACRO_KEYS_FOR_EACH_PLATFORM_v3.XLS
Elite Membership required to download: Hotkeys_3_Platforms_A.txt
Started this thread Reply With Quote
Thanked by:




Last Updated on September 27, 2016


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts