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,992 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

  #1 (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 use AutoHotkey extensively in my trading to automate much of the routine tasks that I have to do during the trading day. I want to include here some of the AutoHotkey scripts I use. AutoHotkey is a free, open-source macro-creation and automation software utility that allows users to automate repetitive tasks, using a simple but powerful interpreted scripting language.

To use AutoHotKey, download and install the software, then run the scripts that will be shared in this thread.

Feel free to share your scripts here as well.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
Exit Strategy
NinjaTrader
How to apply profiles
Traders Hideout
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Tao te Trade: way of the WLD
24 thanks
Just another trading journal: PA, Wyckoff & Trends
23 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #2 (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

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

Started this thread Reply With Quote
  #3 (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


As a scalper I found I wanted to be able to quickly switch from one monitor, to a chart on another monitor far away, in order to enter a quick trade. Dragging the mouse across multiple monitors, and finding the buy button on that chart often took longer then I wanted. So, I created some hotkeys to quickly switch to specific charts on specific monitors.

I personally use 3 monitors, but in this code, I am assuming the use of 6 monitors arranged in 2 rows of 3 monitors, and switching monitors using the Insert/Delete,Home/End, PageUp/PageDn Navigation keys. I sometime use 2 charts per monitor, where each chart occupies the right or left half of the screen. A single click on a particular navigation key will go to chart1 on that monitor, a double click of the same key will go to chart2 on that same monitor. You can change the numbers and positions to allow for different amount of monitors and/or configurations

 
Code
;#################################################################
;###
;### Hotkeys to send the cursor to specific monitors
;###
;#################################################################

;###
;### Inits
;###
CoordMode, Mouse, Screen	;### Mouse positioning mode is for entire desktop

    ;###
    ;###  Get Monitor positions
    ;###
SysGet, Monitors, MonitorCount
Loop, %Monitors%
{
  SysGet, M%A_Index%_Name, MonitorName, %A_Index%
  SysGet, Monitor%A_Index%, MonitorWorkArea, %A_Index%
  M%A_Index%_Width  := Monitor%A_Index%Right  - Monitor%A_Index%Left
  M%A_Index%_Height := Monitor%A_Index%Bottom - Monitor%A_Index%Top
  desktopWidth += M%A_Index%_Width

  x1 := Monitor%A_Index%Left  + 100	;### Chart1 xposition
  x2 := Monitor%A_Index%Right - 100	;### Chart2 xposition
  y  := Monitor%A_Index%Top   + 650	;### Charts yposition

    ;###
    ;### Main or Middle Row of monitors
    ;###
  if ( Monitor%A_Index%Top == 0 ) { 
      ;### Left Monitor
    if ( Monitor%A_Index%Left < 0 ) { 
       MidLeft_Chart1 = %x1%, %y%	;### Left Monitor, Chart 1	
       MidLeft_Chart2 = %x2%, %y%	;### Left Monitor, Chart 2
    }
      ;### Center Monitor
    else if ( Monitor%A_Index%Left == 0 ) {
       MidCenter_Chart1 = %x1%, %y%
       MidCenter_Chart2 = %x2%, %y%
    }
      ;### Right Monitor
    else {
       MidRight_Chart1 = %x1%, %y%
       MidRight_Chart2 = %x2%, %y%
    }
  }
    ;###
    ;### Top/Higher Row of monitors
    ;###
  if ( Monitor%A_Index%Top < 0 ) { 
       ;### Left Monitor
    if ( Monitor%A_Index%Left < 0 ) { 
       TopLeft_Chart1 = %x1%, %y%
       TopLeft_Chart2 = %x2%, %y%
    }
      ;### Center Monitor
    else if ( Monitor%A_Index%Left == 0 ) {
       TopCenter_Chart1 = %x1%, %y%
       TopCenter_Chart2 = %x2%, %y%
    }
      ;### Right Monitor
    else {
       TopRight_Chart1 = %x1%, %y%
       TopRight_Chart2 = %x2%, %y%
    }
  }


    ;###
    ;### Bottom/Lower Row of monitors
    ;###
  if ( Monitor%A_Index%Top > 0 ) { 
       ;### Left Monitor
    if ( Monitor%A_Index%Left < 0 ) { 
       BotLeft_Chart1 = %x1%, %y%
       BotLeft_Chart2 = %x2%, %y%
    }
      ;### Center Monitor
    else if ( Monitor%A_Index%Left == 0 ) {
       BotCenter_Chart1 = %x1%, %y%
       BotCenter_Chart2 = %x2%, %y%
    }
      ;### Right Monitor
    else {
       BotRight_Chart1 = %x1%, %y%
       BotRight_Chart2 = %x2%, %y%
    }
  }
}

    ;###
    ;### Assign keys to various monitors
    ;###
  Insert::
    goto_monitor( "TopLeft" ) 
    return

  Delete::
    goto_monitor( "MidLeft" ) 
    return

  Home::
    goto_monitor( "TopCenter" ) 
    return

  End::
    goto_monitor( "MidCenter" ) 
    return

  PgUp::
    goto_monitor( "TopRight" ) 
    return

  PgDn::
    goto_monitor( "MidRight" ) 
    return

;###
;### Switch monitor function
;###
goto_monitor( monitor ) 
{
  global
  ;local ninjaActive := 0
  ;WinGetActiveTitle, activeWin 
  ;if ( RegExMatch(activeWin, ".*?\(.*?\).*?\d+/\d+/\d+") or RegExMatch(activeWin, "Control Center - ") )	;### NinjaTrader Chart or Control Center
  {
     if ( GetKeyState("ScrollLock","T") ) {	;### Insure Scroll Lock Key is ON
       ninjaActive := 1

       if ( A_ThisHotkey = A_PriorKey and A_TickCount - lastKeyTime < 500 ) {
          keyClickCount++
       }
       else {
          keyClickCount := 1
       }

       if ( keyClickCount == 1 ) {		;### Single Click - Activate chart1
          screenXY := %monitor%_Chart2
       }
       else if ( keyClickCount >= 2 ) {		;### Double Click - Activate chart2
          screenXY := %monitor%_Chart1
       }
       Send {Click %screenXY%, Right}{Escape}
     }
     else Send, {%A_ThisHotkey%}		;### Send normal key

     lastKeyTime := A_TickCount
  }
}

Started this thread Reply With Quote
  #4 (permalink)
 
perryg's Avatar
 perryg 
Rechovot
 
Experience: Advanced
Platform: NinjaTrader
Broker: CQG
Trading: Index,Currency and Energy futures
Posts: 1,644 since Jan 2010
Thanks Given: 508
Thanks Received: 6,288


monpere View Post
As a scalper I found I wanted to be able to quickly switch from one monitor, to a chart on another monitor far away, in order to enter a quick trade. Dragging the mouse across multiple monitors, and finding the buy button on that chart often took longer then I wanted. So, I created some hotkeys to quickly switch to specific charts on specific monitors.

I personally use 3 monitors, but in this code, I am assuming the use of 6 monitors arranged in 2 rows of 3 monitors, and switching monitors using the Insert/Delete,Home/End, PageUp/PageDn Navigation keys. I sometime use 2 charts per monitor, where each chart occupies the right or left half of the screen. A single click on a particular navigation key will go to chart1 on that monitor, a double click of the same key will go to chart2 on that same monitor. You can change the numbers and positions to allow for different amount of monitors and/or configurations

 
Code
;#################################################################
;###
;### Hotkeys to send the cursor to specific monitors
;###
;#################################################################

;###
;### Inits
;###
CoordMode, Mouse, Screen	;### Mouse positioning mode is for entire desktop

    ;###
    ;###  Get Monitor positions
    ;###
SysGet, Monitors, MonitorCount
Loop, %Monitors%
{
  SysGet, M%A_Index%_Name, MonitorName, %A_Index%
  SysGet, Monitor%A_Index%, MonitorWorkArea, %A_Index%
  M%A_Index%_Width  := Monitor%A_Index%Right  - Monitor%A_Index%Left
  M%A_Index%_Height := Monitor%A_Index%Bottom - Monitor%A_Index%Top
  desktopWidth += M%A_Index%_Width

  x1 := Monitor%A_Index%Left  + 100	;### Chart1 xposition
  x2 := Monitor%A_Index%Right - 100	;### Chart2 xposition
  y  := Monitor%A_Index%Top   + 650	;### Charts yposition

    ;###
    ;### Main or Middle Row of monitors
    ;###
  if ( Monitor%A_Index%Top == 0 ) { 
      ;### Left Monitor
    if ( Monitor%A_Index%Left < 0 ) { 
       MidLeft_Chart1 = %x1%, %y%	;### Left Monitor, Chart 1	
       MidLeft_Chart2 = %x2%, %y%	;### Left Monitor, Chart 2
    }
      ;### Center Monitor
    else if ( Monitor%A_Index%Left == 0 ) {
       MidCenter_Chart1 = %x1%, %y%
       MidCenter_Chart2 = %x2%, %y%
    }
      ;### Right Monitor
    else {
       MidRight_Chart1 = %x1%, %y%
       MidRight_Chart2 = %x2%, %y%
    }
  }
    ;###
    ;### Top/Higher Row of monitors
    ;###
  if ( Monitor%A_Index%Top < 0 ) { 
       ;### Left Monitor
    if ( Monitor%A_Index%Left < 0 ) { 
       TopLeft_Chart1 = %x1%, %y%
       TopLeft_Chart2 = %x2%, %y%
    }
      ;### Center Monitor
    else if ( Monitor%A_Index%Left == 0 ) {
       TopCenter_Chart1 = %x1%, %y%
       TopCenter_Chart2 = %x2%, %y%
    }
      ;### Right Monitor
    else {
       TopRight_Chart1 = %x1%, %y%
       TopRight_Chart2 = %x2%, %y%
    }
  }


    ;###
    ;### Bottom/Lower Row of monitors
    ;###
  if ( Monitor%A_Index%Top > 0 ) { 
       ;### Left Monitor
    if ( Monitor%A_Index%Left < 0 ) { 
       BotLeft_Chart1 = %x1%, %y%
       BotLeft_Chart2 = %x2%, %y%
    }
      ;### Center Monitor
    else if ( Monitor%A_Index%Left == 0 ) {
       BotCenter_Chart1 = %x1%, %y%
       BotCenter_Chart2 = %x2%, %y%
    }
      ;### Right Monitor
    else {
       BotRight_Chart1 = %x1%, %y%
       BotRight_Chart2 = %x2%, %y%
    }
  }
}

    ;###
    ;### Assign keys to various monitors
    ;###
  Insert::
    goto_monitor( "TopLeft" ) 
    return

  Delete::
    goto_monitor( "MidLeft" ) 
    return

  Home::
    goto_monitor( "TopCenter" ) 
    return

  End::
    goto_monitor( "MidCenter" ) 
    return

  PgUp::
    goto_monitor( "TopRight" ) 
    return

  PgDn::
    goto_monitor( "MidRight" ) 
    return

;###
;### Switch monitor function
;###
goto_monitor( monitor ) 
{
  global
  ;local ninjaActive := 0
  ;WinGetActiveTitle, activeWin 
  ;if ( RegExMatch(activeWin, ".*?\(.*?\).*?\d+/\d+/\d+") or RegExMatch(activeWin, "Control Center - ") )	;### NinjaTrader Chart or Control Center
  {
     if ( GetKeyState("ScrollLock","T") ) {	;### Insure Scroll Lock Key is ON
       ninjaActive := 1

       if ( A_ThisHotkey = A_PriorKey and A_TickCount - lastKeyTime < 500 ) {
          keyClickCount++
       }
       else {
          keyClickCount := 1
       }

       if ( keyClickCount == 1 ) {		;### Single Click - Activate chart1
          screenXY := %monitor%_Chart2
       }
       else if ( keyClickCount >= 2 ) {		;### Double Click - Activate chart2
          screenXY := %monitor%_Chart1
       }
       Send {Click %screenXY%, Right}{Escape}
     }
     else Send, {%A_ThisHotkey%}		;### Send normal key

     lastKeyTime := A_TickCount
  }
}

I have implemented this script, and it does not seem to work at all. I am still using XP profressional, so maybe this could be the problem. I have other small scripts that work, so it must be something in the code that is not reading the window system calls correctly.

Reply With Quote
Thanked by:
  #5 (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


perryg View Post
I have implemented this script, and it does not seem to work at all. I am still using XP profressional, so maybe this could be the problem. I have other small scripts that work, so it must be something in the code that is not reading the window system calls correctly.

I am using Windows Vista. Many of the more advanced built in functions in AutoHotKey return null or 0 with older Windows versions 95/98/ME/NT/2000/XP. You may want to simplify the script by removing the monitor configuration calls and replacing the monitor dimension variables with hardcoded values, i.e. replacing:

'TopLeft_Chart2 = %x2%, %y%' with 'TopLeft_Chart2 = -100, 650'
'MidCenter_Chart2 = %x2%, %y%' with 'MidCenter_Chart2 = 950, 650'

etc.

Also, make sure the 'Scroll Lock' key is set to ON (Scroll Lock LED is lit on the keyboard), the script ignores hot keys, when scroll lock is off.

Started this thread Reply With Quote
  #6 (permalink)
 
Shivaya's Avatar
 Shivaya 
Belfast N.Ireland and Brisbane Australia
 
Experience: Advanced
Platform: NinjaTrader
Broker: Stage 5
Trading: ES
Posts: 128 since Jun 2009
Thanks Given: 84
Thanks Received: 489

Just watched a video about upgrading trading computers and one survey says 60% traders still using XP. (2001 technology) I was one. So I recently and finally upgraded from XP to Windows 7 64 bit with i7 3770k processor with internet of 63MB download/12mb upload.

Smooth As

Reply With Quote
  #7 (permalink)
 
perryg's Avatar
 perryg 
Rechovot
 
Experience: Advanced
Platform: NinjaTrader
Broker: CQG
Trading: Index,Currency and Energy futures
Posts: 1,644 since Jan 2010
Thanks Given: 508
Thanks Received: 6,288


monpere View Post
I am using Windows Vista. Many of the more advanced built in functions in AutoHotKey return null or 0 with older Windows versions 95/98/ME/NT/2000/XP. You may want to simplify the script by removing the monitor configuration calls and replacing the monitor dimension variables with hardcoded values, i.e. replacing:

'TopLeft_Chart2 = %x2%, %y%' with 'TopLeft_Chart2 = -100, 650'
'MidCenter_Chart2 = %x2%, %y%' with 'MidCenter_Chart2 = 950, 650'

etc.

Also, make sure the 'Scroll Lock' key is set to ON (Scroll Lock LED is lit on the keyboard), the script ignores hot keys, when scroll lock is off.

Thanks. No change, so maybe it is the Windows calls on the XP

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


perryg View Post
Thanks. No change, so maybe it is the Windows calls on the XP

@perryg,

Put the following 3 lines after the line that says 'desktopWidth += M%A_Index%_Width'

l := Monitor%A_Index%Left
t := Monitor%A_Index%Top
MsgBox Monitor %A_Index% at %l%, %t%


This should popup a message that shows the x,y location for each of your monitors found on your extended desktop. On my machine it returns "Monitor 1 at 0,0", "Monitor 2 at 1024,0", "Monitor 3 at -1280,0"

If it doesn't return anything, or all zeros, then the system calls are returning default 0 values on Windows XP.

Started this thread Reply With Quote
  #9 (permalink)
 
perryg's Avatar
 perryg 
Rechovot
 
Experience: Advanced
Platform: NinjaTrader
Broker: CQG
Trading: Index,Currency and Energy futures
Posts: 1,644 since Jan 2010
Thanks Given: 508
Thanks Received: 6,288


monpere View Post
@perryg,

Put the following 3 lines after the line that says 'desktopWidth += M%A_Index%_Width'

l := Monitor%A_Index%Left
t := Monitor%A_Index%Top
MsgBox Monitor %A_Index% at %l%, %t%


This should popup a message that shows the x,y location for each of your monitors found on your extended desktop. On my machine it returns "Monitor 1 at 0,0", "Monitor 2 at 1024,0", "Monitor 3 at -1280,0"

If it doesn't return anything, or all zeros, then the system calls are returning default 0 values on Windows XP.

Thank you for your efforts, but there is no response even to the window message. So it must be the XP setup

Reply With Quote
  #10 (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 don't trade the news, but a couple of weeks ago, I almost got caught in an unusual market move which seems was a reaction to a Bernanke speech. I normally use the MarketReminders indicator to put reminders on my charts of scheduled market events such as FOMC days, Contract Rollover dates, Crude Oil Inventory, and certain other reports etc., but I don't normally care about other market news and most reports.

So, I wrote this little script that goes out to Econoday and ForexFactory sites and alerts me of certain events for that day. Namely it looks for any events that mentions 'FOMC', or 'Bernanke'. It pops up a message showing the entry for any such events it finds for the current day. This script is run automatically every morning. You can change it to search for any term that is important to you.

This script actually does not have any hotkeys, it runs once and then exits.

 
Code
;######################################
;###
;### Check mam.econonday.com and Forex Factory 
;### for FOMC/Bernake events for today
;###
;######################################

msg := get_news_events("FOMC,Bernanke")	;### Get Fed events
if ( msg != "" ) {
   MsgBox %msg%
}
else MsgBox No News Events

;###
;### Get News Events
;###
get_news_events( events ) 
{
    ;### EconoDay
   msg :=""
   str  := get_url("http://mam.econoday.com/byday.asp?cust=mam&day=%A_DD%&month=%A_MM%&year=%A_YYYY%")
  ;str  := get_url("http://mam.econoday.com/byday.asp?cust=mam&day=31&month=8&year=2012") ;### For Testing
   Loop, parse, events, `, , %A_Space%%A_Tab%
   {
      pattern := "iP)\d+:\d+.*?" . A_LoopField
      index := RegExMatch(str, pattern)
      if ( index > 0 ) { 
         str := SubStr(str,index)
         msg := "Eononday Event`r`n" . SubStr(str,1,RegExMatch(str, "\n")) . "`r`n`r`n"
      }
   }
    ;### ForexFactory
   str := get_url("http://www.forexfactory.com")
  ;str := get_url("http://www.forexfactory.com/index.php?day=aug31.2012") ;### For Testing
   Loop, parse, events, `, , %A_Space%%A_Tab%
   {
      pattern := "iP)\d+:\d+.*?" . A_LoopField
      index := RegExMatch(str, pattern)
      if ( index > 0 ) {
         str := SubStr(str,index)
         msg := msg . "ForexFactory Event`r`n" . SubStr(str,1,RegExMatch(str, "\n")) . "`r`n`r`n"
      }
   }

   return, msg
}


;###
;### 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
   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")  
}

ExitApp

Started this thread Reply With Quote




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