AutoHotkey Scripts - NinjaTrader | futures io social trading
futures io futures trading


AutoHotkey Scripts
Updated: Views / Replies:11,725 / 41
Created: by monpere Attachments:4

Welcome to futures io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike

Reply
 4  
 
Thread Tools Search this Thread
 

AutoHotkey Scripts

  #41 (permalink)
Trading Apprentice
Singapore
 
Futures Experience: None
Platform: NinjaTrader
Favorite Futures: Crude CL
 
Posts: 1 since Oct 2016
Thanks: 2 given, 1 received

NT8 AHK Replay

I upgraded the Autohotkey to work with NinjaTrader 8. Basically it just uses Ctrl-TAB to reset the tab fields, tabs into the number and increments.

It only works from 10-31, as I didn't code in padding zeros. And I hard-coded the 2016 year.

Modified from Peresai's script

 
Code

WinWait, Historical Data, 
IfWinNotActive, Historical Data, , WinActivate, Historical Data, 
WinWaitActive, Historical Data,
;
;  Setup Initial State, -- Edit as appropriate before running.
;
StartDate = 12 ; This is the 1st date to process. (YYYYMMDD format )
LoopCnt = 10		; times to loop (number of days from 1st day to download)
EndDate = %StartDate%
;EndDate += %LoopCnt%, days	; This is the last date to process
DownLoadTime = 220		; Seconds to wait before next step  ( Minimun 10 )
Instrument = "CL 11-16"		; Instrument to download '1st letter only down arrow {Down} for next

;				; {Down n} for n down arrows.
ProcessDate = %StartDate%	; Set Currently Processing Date
Loops = %LoopCnt%
;
outputdebug, "Start [": %StartDate% ":" %EndDate% ":" %ProcessDate% : %Loops% "]"  ; outputs to DebugView
;
;  Start the sequence
;
StartSeq:
;
WinActivate, Historical Data,
;

; Reset tab location
Send, {LCtrl down}{Tab}{LCtrl up}{LCtrl down}{Tab}{LCtrl up}


; Get to the Date Field (assuming Download was last selected)  
  Send, {Tab}{Tab}{Tab}{Tab}{Tab}

; clear the date
  Send, {Right}{Right}{Right}{Right}{Right}{Right}{Right}{Right}
  Send, {Backspace}{Backspace}{Backspace}{Backspace}{Backspace}{Backspace}{Backspace}

; Add new date and year
  send, %ProcessDate%2016{TAB}{Enter}

outputdebug, "Sent [": %TimeString% ":" %ProcessDate% "]"
;
;  Twin Powers Activate
;
; Sleep, 2000                     ; 2 seconds to see the data request box
; send, {Enter}          
         ; pushes the Enter button
; Sleep, 5000                     ; 5 second delay
; send, {Enter}                   ; clears the "No data available" box if present
;
;   Update Current Date
;
; ProcessDate += 1, days
ProcessDate += 1
ToolTip %ProcessDate%
;
;   Wait for download to occur	
;
   x := DownLoadTime * 1000
   sleep, %x%
;  sleep, 500
;

;   next itteration
;
outputdebug, "Compare [": %ProcessDate% ":" %EndDate% : %Loops% "]"
Loops -= 1
 if ( Loops > 0 ) { 
outputdebug, "Loop again"
	goto StartSeq
	}
;
;   Thats all she wrote.
;
outputdebug, "All Done [": %TimeString% ":" %ProcessDate% ":" %EndDate% ":" %Loops% "]"   ; outputs to DebugView

 exit

Reply With Quote
The following user says Thank You to loopit for this post:
 
  #42 (permalink)
Elite Member
Brisbane + Queensland/Australia
 
Futures Experience: Beginner
Platform: NinjaTrader, Sierra Chart
Broker/Data: CQG, IQFeed
Favorite Futures: S&P Emini Futures
 
Posts: 54 since Mar 2015
Thanks: 37 given, 66 received

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

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.


 
Code
; --------- 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 http://www.keyboardtrader.com/customized-trading-keyboard.html. It is a access-IS 15 x 8 base. See layout picture




This can be used to setup any programmable keyboard. Modify to suit your needs and number of platforms.




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
AutoHotkey Scripts-trading-keyboard-hotkeys.png  
Attached Files
Register to download File Type: xls MACRO_KEYS_FOR_EACH_PLATFORM_v3.XLS (10.0 KB, 6 views)
Register to download File Type: txt Hotkeys_3_Platforms_A.txt (2.3 KB, 2 views)

Last edited by SilverFut; October 8th, 2016 at 08:42 PM.
Reply With Quote
The following user says Thank You to SilverFut for this post:

Reply



futures io > > > > AutoHotkey Scripts

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

FIO Journal Challenge featuring NinjaTrader ($2,000+ of prizes)

May
 

Portfolio Diversification w/Brendon Delate @ Diversify Portfolio

Elite only

An overview of volumetric analytical tools w/Sergey Sokolov @ PTMC

Elite only

John Hoagland (TBA)

Elite only

FuturesTrader71 Extended Ask Me Anything (AMA)

Elite only

Pete @ Jigsaw Trading (TBA)

Elite only

John @ No BS Day Trading (TBA)

Elite only

An Afternoon with FIO member Softsoap (being rescheduled)

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
ninja & AutoHotKey for order entrys bobarian NinjaTrader 55 April 6th, 2016 02:59 PM
Some Matlab scripts around vwap wh Matlab, R project and Python 6 July 21st, 2015 06:56 PM
Get Autohotkey to work with Sierra Chart? vegasfoster Sierra Chart 2 March 21st, 2011 03:54 AM
Public class, passing values between scripts tinkerz NinjaTrader Programming 2 May 11th, 2010 11:41 AM
Communicate Between Scripts webart NinjaTrader Programming 6 April 30th, 2010 02:42 PM


All times are GMT -4. The time now is 04:36 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-05-25 in 0.10 seconds with 21 queries on phoenix via your IP 54.162.44.105