NexusFi: Find Your Edge


Home Menu

 





AutoHotkey Scripts


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one monpere with 23 posts (98 thanks)
    2. looks_two traderap101 with 13 posts (12 thanks)
    3. looks_3 trendisyourfriend with 12 posts (0 thanks)
    4. looks_4 perryg with 6 posts (2 thanks)
      Best Posters
    1. looks_one monpere with 4.3 thanks per post
    2. looks_two traderap101 with 0.9 thanks per post
    3. looks_3 SilverFut with 0.7 thanks per post
    4. looks_4 perryg with 0.3 thanks per post
    1. trending_up 35,551 views
    2. thumb_up 115 thanks given
    3. group 35 followers
    1. forum 64 posts
    2. attach_file 10 attachments




 
Search this Thread

AutoHotkey Scripts

  #31 (permalink)
 
monpere's Avatar
 monpere 
Bala, PA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus, IB
Trading: SPY, Oil, Euro
Posts: 1,854 since Jul 2010
Thanks Given: 300
Thanks Received: 3,371


lllusion View Post
I did it manually and it worked so it probably is indeed a timing issue. Here's your code I have entered in:

I attempted to put the set key delay in there but it didn't work --- I'm guessing I didn't enter it in right. Can you put it in there for me so I can copy and paste it over? Thanks again kind sir! In the meantime I will start reading some of their manual online.

You have some other code in there that are not relevant. Try the following code. It puts a 1 sec delay between each keystroke.

 
Code
;###
;### Control-B-Left Mouse Key -> Ninjatrader Buy at cursor price level on the chart
;###
;SetKeyDelay, 500

^b::
if ( GetKeyState("ScrollLock",   "T") ) {	;### Insure Scroll Lock Key is ON
   if ( GetKeyState("LControl",  "D") ) {	;### Insure Control Key Key is Down
      if ( GetKeyState("LButton","D") ) {	;### Insure Left Mouse  Key is Down
        ;Send {Escape}{Click Up Left}{Click Up Right}{b}{Enter}{Escape}
         Send {Escape}
         Sleep, 1000
         Send {Click Up Left}
         Sleep, 1000
         Send {Click Up Right}
         Sleep, 1000
         Send {b}
         Sleep, 1000
         Send {Enter}
         Sleep, 1000
         Send {Escape}
      }
   }
}
return

;###
;### Control-S-Left Mouse Key -> Ninjatrader Sell at cursor price level on the chart
;###
^s::
if ( GetKeyState("ScrollLock",   "T") ) {	;### Insure Scroll Lock Key is ON
   if ( GetKeyState("LControl",  "D") ) {	;### Insure Control Key Key is Down
      if ( GetKeyState("LButton","D") ) {	;### Insure Left Mouse  Key is Down
        ;Send {Escape}{Click Up Left}{Click Up Right}{s}{Enter}{Escape}
         Send {Escape}
         Sleep, 1000
         Send {Click Up Left}
         Sleep, 1000
         Send {Click Up Right}
         Sleep, 1000
         Send {s}
         Sleep, 1000
         Send {Enter}
         Sleep, 1000
         Send {Escape}
      }
   }
}
return

Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Deepmoney LLM
Elite Quantitative GenAI/LLM
Futures True Range Report
The Elite Circle
Exit Strategy
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
ZombieSqueeze
Platforms and Indicators
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
GFIs1 1 DAX trade per day journal
18 thanks
  #32 (permalink)
 
lllusion's Avatar
 lllusion 
Knoxville, TN
 
Experience: Beginner
Platform: NT7
Trading: SPY
Posts: 34 since Dec 2012
Thanks Given: 12
Thanks Received: 22

I tried it with the delay and it simply did it slower, without actually triggering a sell limit. It just opens the "confirm order placement" y/n box then it closes without putting the sell limit in. It's so weird because when I do the exact same thing for the buy limit, it works.

This is a big bummer because this is an extremely useful hotkey to have... should I just try reinstalling ninjatrader or something? I don't think there is anything wrong with your code.

Reply With Quote
  #33 (permalink)
 
monpere's Avatar
 monpere 
Bala, PA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus, IB
Trading: SPY, Oil, Euro
Posts: 1,854 since Jul 2010
Thanks Given: 300
Thanks Received: 3,371



lllusion View Post
I tried it with the delay and it simply did it slower, without actually triggering a sell limit. It just opens the "confirm order placement" y/n box then it closes without putting the sell limit in. It's so weird because when I do the exact same thing for the buy limit, it works.

This is a big bummer because this is an extremely useful hotkey to have... should I just try reinstalling ninjatrader or something? I don't think there is anything wrong with your code.

You did not mention order confirmation before. Looks like you have Order Confirmation active and the order confirmation pop-up window is receiving some of the key strokes, causing the unintended behavior. The script is not intended to work with Order Confirmation given that its purpose is to enter orders quickly. If you turn off order confirmation, I think it should work as designed. To turn off order confirmation go to Tools->Options->General Tab, and De-Select 'Confirm Order Placement'

Started this thread Reply With Quote
Thanked by:
  #34 (permalink)
 
lllusion's Avatar
 lllusion 
Knoxville, TN
 
Experience: Beginner
Platform: NT7
Trading: SPY
Posts: 34 since Dec 2012
Thanks Given: 12
Thanks Received: 22

Aaaah I understand. I was not aware you could turn off order confirmation. Will do this. Thanks again.

Reply With Quote
  #35 (permalink)
 
monpere's Avatar
 monpere 
Bala, PA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus, IB
Trading: SPY, Oil, Euro
Posts: 1,854 since Jul 2010
Thanks Given: 300
Thanks Received: 3,371

I roll over futures contracts based on volume. I wrote the following NinjaTrader indicators, RolloverVolume and BarChartDotComVolumes so i can determine which contracts have the highest volume for my traded instruments. But given that I use this functionality only once a month for monthly contracts or once every 3 months for quarterly contracts, there's no real reason why I want these indicators on my charts the rest of the time, even though I wrote them in such a way to use minimal resources.

So, I wrote this AutoHotkey script to duplicate the latter indicator and get the contracts volume from barchart.com without involving NinjaTrader at all, therefore it can be used with any trading platform. I can just run the script on demand, once a month to determine which contract I want to trade. It gets end of day volume by default, or you can pass an "I" as a command line argument in order to get intraday volume instead. You can update the list of instruments in the code.

Note: The code may need to be updated, if barchart.com changes the format of the associated web page in the future.

 
Code
;###
;### Get the highest contract front month volumes from barchart.com
;###

volmode := "D"			;### Volume mode D=EndOfDay, I=IntraDay
voltype := "EndOfDay"
result  := ""
Loop, %0%  {
    param := %A_Index%
	if ( RegExMatch(param, "^I") ) {
		volmode := "I"			;### IntraDay Volume
		voltype := "IntraDay"
	}
}

months := "JanFebMarAprMayJunJulAugSepOctNovDec"

get_symbols("CL, GC, YG, NQ, X, B6, E6, DX, RJ")	;### Symbols List

ToolTip
MsgBox, 64, , Contracts with Highest %voltype% Volumes`n`n%result%

ExitApp

get_symbols( symbols ) 
{
	global
	Loop, parse, symbols, `, , %A_Space%%A_Tab%
	{
		symbol = %A_LoopField%
		ToolTip,`n      ...Getting %symbol% %voltype% Volume...        `n`n   `n`n, 300, 500
		url  = http://www.barchart.com/commodityfutures/%symbol%?mode=%volmode%&view=&_dts1=volume
		str := get_url(url)
		RegExMatch(str, "s)/quotes/futures/" . %symbol% . ".*?title.*?=(.*?)>\s*(.*?)\s+.*?\((...).*?(\d+).*?ds_volume.*?(\d.*?)<", Match)
		title    := Match1
		contract := Match2
		month    := Match3
		year     := Match4
		volume   := Match5
		SetFormat, Float, 02.0	;### For 2 digit numeric month format
		mon      := Floor(RegExMatch(months, month)/3)+1.0
		result    = %result%%symbol%`t%mon%-%year%`t%contract%`t%volume%`t%title%`n
	}
	return
}


;######################################
;###
;### Get Web Page Text
;###
;######################################
get_url(url, line=""){
   doc := ComObjCreate("HTMLfile")
   pwhr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
   pwhr.Open("GET",url) 
   pwhr.Send()
   doc.write(pwhr.ResponseText)
  ;text := doc.body.outerText
   text := doc.body.outerHTML
   if not line
      return, text
   s := InStr(text, "`n", 0, 1, line-1)
   e := InStr(text, "`n", 0, s+1)
   return, Trim(SubStr(text, s+1, e-s-1), "`r`n")  
}

;###
;### Exit Script
;###

^x::
MsgBox, 3, , .                           Terminate Rollover_Volume?, 1000
IfMsgBox Yes 
{
  ExitApp
}
return

Started this thread Reply With Quote
  #36 (permalink)
 swinger 
Raleigh NC/USA
 
Experience: Beginner
Platform: NinjaTrader
Trading: stocks
Posts: 33 since Oct 2014
Thanks Given: 212
Thanks Received: 16

Anyone familiar with modifying indicators via AutoHotKey?

In a NT chart, I'd like to be able to automate the process of bringing up the indicators window (easy enough) and then going through every indicator on the chart and toggling "Update on Bar Close" between True and False.

This would be useful to avoid the resource demands of constantly running realtime charts with Update on Bar Close set to False, but would still provide a means of quickly seeing the current indicators levels if the current bar were closed right now.

Reply With Quote
  #37 (permalink)
kitcaptain
Hong Kong
 
Posts: 3 since May 2015
Thanks Given: 2
Thanks Received: 0

Hi Monpere,

Your script - Free Stock historical Tick Data

Thanks very much for posting these very useful scripts. Have been researching Netfonds myself today and looked by chance if somebody else had tackled this same exercise.

As a very novice coder I had difficulty getting this to work. Displayed the first confirmation MsgBox and nothing more.

Would you please provide an example of how I would personalise your script to request UVXY, XIV and SPY?

Many thanks and regards,
Andrew

Reply With Quote
  #38 (permalink)
chinmaya122
Amsterdam , Netherlands
 
Posts: 15 since Mar 2016
Thanks Given: 1
Thanks Received: 3


monpere View Post
Several people have discussed how to quickly place orders on Ninjatrader charts. I do this using the following script. It basically issues Ninjatrader buy/sell stop or limit using the NT chart trading cursor menu. Autohotkey scripts are designed to normally run in the background as stay resident programs, so you generally run the script once, it stays in memory, and you can repeatedly use the programmed hot key sequence to perform the desired function.

In my scripts I generally require the 'Scroll Lock' key to be set for any hot key to be executed. This prevents accidental executions. When I see the Scroll Lock LED is turned On, on my keyboard, I know my keyboard is live.
In the following script, I require that the user presses down the left mouse key at the desired price level and hit Control-B for buy, or Control-S for sell. This should prevent your cat from walking across the keyboard and entering a trade

 
Code
;###
;### Control-B-Left Mouse Key -> Ninjatrader Buy at cursor price level on the chart
;###
^b::
if ( GetKeyState("ScrollLock",   "T") ) {	;### Insure Scroll Lock Key is ON
   if ( GetKeyState("LControl",  "D") ) {	;### Insure Control Key Key is Down
      if ( GetKeyState("LButton","D") ) {	;### Insure Left Mouse  Key is Down
         Send {Escape}{Click Up Left}{Click Up Right}{b}{Enter}{Escape}
      }
   }
return

;###
;### Control-S-Left Mouse Key -> Ninjatrader Sell at cursor price level on the chart
;###
^s::
if ( GetKeyState("ScrollLock",   "T") ) {	;### Insure Scroll Lock Key is ON
   if ( GetKeyState("LControl",  "D") ) {	;### Insure Control Key Key is Down
      if ( GetKeyState("LButton","D") ) {	;### Insure Left Mouse  Key is Down
         Send {Escape}{Click Up Left}{Click Up Right}{s}{Enter}{Escape}
      }
   }
}
return

I want to modify this by having a simple mouse click + key press to buy and sell. I dont want to use the control key. Can you please share the modified code ?
Is it possible to have the Char Z to buy and Char X to sell , instead of B to buy and S to sell .

Reply With Quote
  #39 (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

Can someone please let me know if the following is possible with AutoHotKey.


My issue is that I'm trying to see if it can function as I need if I try and setup a trading keyboard ( Trading Keyboard | Sample Configurations | Keyboard Trader) with 3 separate macros for each key press that will then send the same action to 3 separate platforms.
(1 = Sierra Charts running IQFeed (SIM), 2 = Sierra Charts running CQG (LIVE), 3 = NinjaTrader 8 running IQFeed (SIM).)
I've switch the majority of my trading over to Sierra Charts but I've had to keep NT for Jigsaw DOM which I use to find entries/exits. I've been executing on Sierra Charts with the CQG broker data but I'm finding it difficult when scalping to track the exact price level of my live order entry and stop price level (that's on SC) while looking at the Jigsaw DOM on NT.

So I started looking around for some option that would allow a macro button solution so that when I entered a live trade on Sierra Charts w/CQG broker data, that same order would be entered as a SIM trade on Sierra Charts w/IQFeed and NT8 w/IQFeed and show the same order price levels on the Jigsaw DOM as the order price levels on the live trade on Sierra Charts that is executing the live trade to the broker. Then I only need to closely watch one screen.


The software for the keyboard ( SoftProg Keyboard and Keypad Programming Utility) allows "layering" (Multiple macros) on the same key.

I've been trying to test the concept using the current keyboard I have (Roccat MK Pro) and setup the same macro key sequence (Buy Market = ALT+A) in Sierra Charts and (Buy Market = ALT+A) in Ninjatrader 8. (This would not be the case with the dedicated trading keyboard - each platform would get its own unique macro sequence for each task but the 3 unique macros would be bound to the same key press).


The problem I seem to be running into is that it will only execute the macro on whatever chart that has been clicked on to "bring it to the front" in Windows (Running Windows 8.1). So if I first click on Sierra charts chart, then ALT+A it will execute the Buy order on SC. Then if I click on NT8 chart and press ALT+A, it will execute the Buy order on NT8.

Each platform forces the chart to be clicked on first to become "active" and only then will it accept the macro sequence. I've talked to Sierra Charts support and they said I should explore trying to find a solution with AutoHotKey.

Is it possible to write a hotkey/script so that when a key is pressed (EG for a Buy market order), it will first make the required platform chart "active" and then execute the order on that platform, and that this same process can be executed for 3 separate platforms?

EG
Buy At Market button =
Make Sierra Charts LIVE chart# "active" - Execute Buy order
Make Sierra Charts SIM chart# "active" - Execute Buy order
Make Ninjatrader 8 SIM chart# "active" - Execute Buy order

Macros ideally would be all tied to one button on the keyboard or if that isn't possible, tie each macro to one key-switch and use dual or quad key caps so that 2 or 4 key-switches are activated at the same time. The keyboard in the above link has software that allows "layering" of macros (2 layers) on the same switch. From what I can gather this should allow 3 macros to a switch. Would that software ( SoftProg Keyboard and Keypad Programming Utility ) be able to be used with AutoHotKey?

Is there a solution or workaround to getting this to all work as I've described? Will AutoHotKey be the right path to start going down?

I'm only trying to trade 1 instrument at a time - 30yr Treasuries ZB. But I also have 10yr and 5yr charts and DOMs running over a total of 4 screens.


If there are any more details that might help, please let me know.

Reply With Quote
  #40 (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


For anyone else interested, I came across this that might help others with limited coding ability.

https://autohotkey.com/boards/viewtopic.php?f=6&t=143
Pulover's Macro Creator ? The Complete Automation Tool


I'm still to figure out if it can help with the tasks I need but it looks interesting and might help others.

Reply With Quote
Thanked by:




Last Updated on June 18, 2023


© 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