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

  #11 (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

Slight revision of the above script. The line below:


Quoting 
str := get_url("http://mam.econoday.com/byday.asp?cust=mam&day=%A_DD%&month=%A_MM%&year=%A_YYYY%")

Should be replaced with the following lines:




Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Exit Strategy
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
26 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
22 thanks
My NQ Trading Journal
16 thanks
HumbleTraders next chapter
9 thanks
  #12 (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

Ninjatrader 'Save Workspace' does not seem to save files to disk immediately (bug?). If NT crashes or terminates abnormally, your workspace may not have been saved, and sometimes after crashes, the workspace will be corrupted, and you will have lost your setup. Using 'Save Workspace As' instead does not seem to have this issue, so I created a AuotHotKey script to use save as instead. It saves the workspace as 'zbak<workspace>', then saves it again using the original workspace name, so you have a backup of the workspace with the save operation. The z in the backup name is to force the backup names to sort at the end when listed.

The script also shows how to pop up a user message input box with a timeout, and read the yes, no cancel user response.

 
Code
;######################################
;###
;### Save NinjaTrader Workspace
;###
;### If NT crashes or terminates abnormally, your workspace may not have been saved, and may get corrupted
;### Save workspace as name 'zbak_<worksapce>', then save again with original workspace name
;###
;######################################

;### Control-F3 - Also defined inside NinjaTrader as Save Workspace
~^F3::
   msg := ""
   osWindows := ""
   ntWindows = 
   (
      
   ;###
   ;### Restore NinjaTrader Windows from Last Save
   ;###
   CoordMode, Mouse, Screen
   SetTitleMatchMode 2`n
     ;### Restore NinjaTrader Windows`n
   )

   WinGetActiveTitle, activeWin 
   if ( RegExMatch(activeWin, ".*?\(.*?\).*?\d+/\d+/\d+") or RegExMatch(activeWin, "Control Center - ") ) {	;### NinjaTrader Chart or Control Center
      WinActivate, Control Center -
      WinWaitActive Control Center -
      WinGetActiveTitle, title
      if ( RegExMatch(title, "Control Center - ") ) { 
         workspaceName := RegExReplace(title, "Control Center - ", "") ;### Ninja Conrtrol center and chart windows
          MsgBox, 3, , .                                 Save workspace %workspaceName% ?, 10
          IfMsgBox Yes 
          {
            WinActivate,   %title%
            WinWaitActive  %title%
            IfWinActive,   %title%
            {
              SendInput {Escape}{Alt Down}{f}{Alt Up}{w}{s}{s}{Enter}zbak_%workspaceName%{Enter}{y}
              Sleep 500
              SendInput {Escape}{Alt Down}{f}{Alt Up}{w}{w}{s}{s}{Enter}%workspaceName%{Enter}{y}
            }
          }
      }
   }
return

Started this thread Reply With Quote
  #13 (permalink)
 Morpheus 
Capitol Heights, MD
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Global Futures/eSignal
Trading: ES
Posts: 12 since Apr 2010
Thanks Given: 42
Thanks Received: 11



monpere View Post
...
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
[/code]

Hi, I would like to experiment with this script but cannot get it to work. AutoHotKey complains about line 57, saying that "pwr.ResponseText" contains an illegal character. I am not a programmer but a quick search of your script shows no other reference to that variable. Can you tell me what I might be missing. I am using Windows XP SP3.

Thx

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

With NT, you can scroll a chart horizontally along the time axis using the arrow keys or the mouse wheel, but you cannot scroll a chart vertically along the price axis using these keys. Why not? One of the things I do every day after market is scroll through my charts to review every signal I took and/or missed etc. I also do this to train my eye to see my signals as they are developing by scrolling the candles in one at a time from the right edge of the chart. You can do this exercise with market replay, but I find Market Replay slow, cumbersome, buggy and works only half of the time for me. So, I wrote this AutoHotKey script to scroll a chart vertically using the Up/Down Arrow keys, or Conrtrol-MouseWheel.

 
Code
;###############################################
;###
;### 1. Srcoll NinjaTrader Chart Vertically with Up/Down Arrow keys or Control-Mouse Wheel
;###
;###############################################

;###
;### Inits
;###
CoordMode, Mouse, Screen	;### Mouse positioning mode is for entire desktop
lastWheelTime  := 0


~Up::
   wheelDirection =  1
~Down::
   if ( wheelDirection == 0 ) {
      wheelDirection = -1
   }
lastWheelTime := 0

    ;### NT Chart?
  WinGetTitle, title, A	;### get Window title
  if ( not RegExMatch(title, ".*?\(.*?\).*?\d+/\d+/\d+") ) {
    return
  }

^WheelUp::
   if ( wheelDirection == 0 ) {
      wheelDirection := 1			;### Control Wheel Up
   }

^WheelDown::
   if ( wheelDirection == 0 ) {
      wheelDirection := -1			;### Control Wheel Down
   }

  if ( wheelDirection == 0 ) {
     return
  }

    ;### Restrict to 1 move per 0.5 seconds to prevent mouse wheel from flooding key stream and killing NinjaTrader
  ;zz := A_TickCount - lastWheelTime
  ;ToolTip, TickCount %A_TickCount% lastWheelTime %lastWheelTime% = %zz%, (Width)-500, 500
  if (A_TickCount - lastWheelTime < 500 ) {
    wheelDirection := 0
    return
  }

    ;### Not NT Chart
   WinGetTitle, title, A
   if ( not RegExMatch(title, ".*?\(.*?\).*?\d+/\d+/\d+") ) {
      if ( wheelDirection > 0 ) 
         Send {WheelLeft}
      else
         Send {WheelRight}

      wheelDirection = 0
      return
   }

   ;###
   ;### Scroll NT Chart Up/Down
   ;###
   ;### Get mouse position
  MouseGetPos, mouseX, mouseY,
  WinGetPos,   winX,   winY,  Width, Height, A
  dragX  := winX + Width  - 25
  dragY  := winY + Height - 100			;### winY+300 puts cursor on 'ENTRY' field if chart trader visible

    ;### Init
  SetMouseDelay, 0 
  BlockInput Mouse
  MouseMove, dragX, dragY, 0

    ;### Insure no buttons at drag location, in case chart trader is visible
  MouseGetPos, , , , controlName
  if ( RegExMatch(controlName, "i)(Button|Combo|Edit)") ) {
     BlockInput Off
     MsgBox Active Control '%controlName%' `n   found at window drag location %dragX%, %dragY%`n   Operation not performed
     MouseMove, mouseX, mouseY, 0
     wheelDirection = 0
     return
  }

    ;### Do up/down drag in right price scale
  Send {Escape}
  Send {Control Down}
  MouseClickDrag, Left, dragX, dragY, dragX, dragY-(50*wheelDirection)
  Send {Control Up}

    ;### Do up/down drag again in alternate location in case chart trader is visible
  dragX := dragX - 175
  Send {Escape}
  Send {Control Down}
  MouseClickDrag, Left, dragX, dragY, dragX, dragY-(50*wheelDirection)
  Send {Control Up}

  MouseMove, mouseX, mouseY, 0		;### Move mouse back to original position
  Send {Escape}
  BlockInput Off

    ;### Save wheel motion time
  lastWheelTime := A_TickCount

  wheelDirection = 0
return
By the way I also use a customized version of this awesome NT indicator to scroll charts properly like with the mouse like a truly first rate charting software vendor would implement:


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


Morpheus View Post
Hi, I would like to experiment with this script but cannot get it to work. AutoHotKey complains about line 57, saying that "pwr.ResponseText" contains an illegal character. I am not a programmer but a quick search of your script shows no other reference to that variable. Can you tell me what I might be missing. I am using Windows XP SP3.

Thx

You are probably passing in a weird character to the function, or the website is returning a weird character. If you feel comfortable sharing the info, what is the url of the web page you are trying to access?

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

One of the things I do everyday during, and after market, is markup all my charts with every signal that occurred during the day. I generally use the NT Line Segment Tool, the Ellipse, and the Line Arrow tools to do the majority of this markup. I like the ellipse tool, because you can draw a straight horizontal line, a straight vertical line or a colored ellipse, all using the single ellipse tool. I combine these to show a trade as winner, loser, BE, trail stopped, etc. So, I created this script to remap my mouse buttons to switch between these tools. I use a 5 button mouse, and use the side buttons for this. Single click of the left side button selects the Ellipse tool, a Double Click selects the Line Arrow, a single click of the Right side button deselects any draw tool.

I have also programmed my Middle mouse button to place a trade ruler on the chart, with risk/reward and trade position sizing, but that functionality is programmed in this indicator: TradeRuler, indicator in the nexusfi.com (formerly BMT) download section.

 
Code
;######################################
;###
;### Function key remapings
;###
;######################################

ntLine    = F2
ntArrow   = F3
ntEllipse = F4

;### Set Current NT draw tool
~F2:: 
  ntDrawTool := ntLine		;### Line Segment
return
~F4::
  ntDrawTool := ntEllipse	;### Elipse
return

;######################################
;###
;### Mouse key remapings
;###
;######################################

;### Mouse X2 button - ESC
XButton2::
    Send {Escape}
    lastEscTime := A_TickCount
return

;### Mouse X1 button - Change Ninja Drawing Tool
XButton1::
WinGetTitle, title, A	;### get Window title
if ( RegExMatch(title, ".*?\(.*?\).*?\d+/\d+/\d+") ) { ;### NT Chart?
     if (lastKeyCode = "XButton1" and A_TickCount - lastKeyTime < 500 ) {
       keyClickCount := keyClickCount + 1 
     }
     else {
       keyClickCount := 1
     }

        ;### Single Click - NinjaTrader Ellipse Drawing Tool
     if ( keyClickCount == 1 ) {
        Send {%ntDrawTool%}
     }
        ;### Double Click - NinjaTrader Arrow Drawing Tool
     else if ( keyClickCount == 2 ) {
        Send {%ntArrow%}
     }
}
lastKeyCode := "XButton1"
lastKeyTime := A_TickCount
return

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

Here's how I save my charts. Ctrl-S to save the current chart, Ctrl-Shift-S to save the entire desktop for multiple charts. The image names are automatically named using the chart name, the current date/time, and an optional user specified tag. This might help if you record charts in your journal. This naming convention allows me to list and review charts by date, instrument, or other specific criteria. Uses Microsoft Paint to save the chart window or desktop 'c:\tmp\' folder.

 
Code
;############################################################
;###
;### Save current chart or desctop image to c:\tmp folder
;###
;############################################################
save_type=

^+s::
save_type = (desktop)

^s::
WinGetActiveTitle, activeWin 
if ( GetKeyState("ScrollLock","T") and RegExMatch(activeWin, ".*?\(.*?\).*?\d+/\d+/\d+") )	;### NinjaTrader Chart or Control Center
{
  symbol := SubStr(activeWin,1,RegExMatch(activeWin, " ")-1)
  if ( RegExMatch(save_type, "desktop") ) 
    Send {PrintScreen}	;### Capture entire desktop for multiple charts
  else 
    Send !{PrintScreen}	;### Capture chart window
  Sleep 250

  run mspaint.exe,,Min,pid
  InputBox, tag, Save %save_type% Image Tag
  WinWait, ahk_pid %pid%, ,10

  IfWinExist, ahk_pid %pid%  
  {
    WinActivate 
    WinWaitActive
    WinGet, win_id, ID, A
    Send ^v
    WinMenuSelectItem, ahk_pid %pid%, , File, Save As,
    Sleep 1000
    SendInput c:\tmp\%symbol%_%tag%_%A_MMM%%A_DD%_%A_Hour%h%A_Min%m%A_Sec%.jpg{Enter}
    Sleep 500
    SendInput {y}
    Sleep 500
    SendInput {n}
    WinClose, ahk_id %win_id%
  }
  else  {
     MsgBox Could not start Microsoft Paint to save Print Screen
  }
}

save_type=
return

Started this thread Reply With Quote
  #18 (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
Here's how I save my charts. Ctrl-S to save the current chart, Ctrl-Shift-S to save the entire desktop for multiple charts. The image names are automatically named using the chart name, the current date/time, and an optional user specified tag. This might help if you record charts in your journal. This naming convention allows me to list and review charts by date, instrument, or other specific criteria. Uses Microsoft Paint to save the chart window or desktop 'c:\tmp\' folder.

 
Code
;############################################################
;###
;### Save current chart or desctop image to c:\tmp folder
;###
;############################################################
save_type=

^+s::
save_type = (desktop)

^s::
WinGetActiveTitle, activeWin 
if ( GetKeyState("ScrollLock","T") and RegExMatch(activeWin, ".*?\(.*?\).*?\d+/\d+/\d+") )	;### NinjaTrader Chart or Control Center
{
  symbol := SubStr(activeWin,1,RegExMatch(activeWin, " ")-1)
  if ( RegExMatch(save_type, "desktop") ) 
    Send {PrintScreen}	;### Capture entire desktop for multiple charts
  else 
    Send !{PrintScreen}	;### Capture chart window
  Sleep 250

  run mspaint.exe,,Min,pid
  InputBox, tag, Save %save_type% Image Tag
  WinWait, ahk_pid %pid%, ,10

  IfWinExist, ahk_pid %pid%  
  {
    WinActivate 
    WinWaitActive
    WinGet, win_id, ID, A
    Send ^v
    WinMenuSelectItem, ahk_pid %pid%, , File, Save As,
    Sleep 1000
    SendInput c:\tmp\%symbol%_%tag%_%A_MMM%%A_DD%_%A_Hour%h%A_Min%m%A_Sec%.jpg{Enter}
    Sleep 500
    SendInput {y}
    Sleep 500
    SendInput {n}
    WinClose, ahk_id %win_id%
  }
  else  {
     MsgBox Could not start Microsoft Paint to save Print Screen
  }
}

save_type=
return

Very useful. I have noticed that although you request the image to be a jpg file, it is always a bmp file with the extension jpg. I tried changing to png file in oder to get a smaller file, but it still saves very large bmp files.
Is there a way around this ?

Reply With Quote
  #19 (permalink)
 omaha786 
San Diego, California
 
Experience: Intermediate
Platform: Sierra Chart
Broker: IB, OEC, Optimus, DDT
Trading: ES, ZN
Posts: 221 since Jun 2010
Thanks Given: 512
Thanks Received: 158


monpere View Post
Here's how I save my charts. Ctrl-S to save the current chart, Ctrl-Shift-S to save the entire desktop for multiple charts. The image names are automatically named using the chart name, the current date/time, and an optional user specified tag. This might help if you record charts in your journal. This naming convention allows me to list and review charts by date, instrument, or other specific criteria. Uses Microsoft Paint to save the chart window or desktop 'c:\tmp\' folder.

 
Code
;############################################################
;###
;### Save current chart or desctop image to c:\tmp folder
;###
;############################################################
save_type=

^+s::
save_type = (desktop)

^s::
WinGetActiveTitle, activeWin 
if ( GetKeyState("ScrollLock","T") and RegExMatch(activeWin, ".*?\(.*?\).*?\d+/\d+/\d+") )	;### NinjaTrader Chart or Control Center
{
  symbol := SubStr(activeWin,1,RegExMatch(activeWin, " ")-1)
  if ( RegExMatch(save_type, "desktop") ) 
    Send {PrintScreen}	;### Capture entire desktop for multiple charts
  else 
    Send !{PrintScreen}	;### Capture chart window
  Sleep 250

  run mspaint.exe,,Min,pid
  InputBox, tag, Save %save_type% Image Tag
  WinWait, ahk_pid %pid%, ,10

  IfWinExist, ahk_pid %pid%  
  {
    WinActivate 
    WinWaitActive
    WinGet, win_id, ID, A
    Send ^v
    WinMenuSelectItem, ahk_pid %pid%, , File, Save As,
    Sleep 1000
    SendInput c:\tmp\%symbol%_%tag%_%A_MMM%%A_DD%_%A_Hour%h%A_Min%m%A_Sec%.jpg{Enter}
    Sleep 500
    SendInput {y}
    Sleep 500
    SendInput {n}
    WinClose, ahk_id %win_id%
  }
  else  {
     MsgBox Could not start Microsoft Paint to save Print Screen
  }
}

save_type=
return

Is there a way to auto capture part of the screen based on coordinates and dimensions (x,y,w,h)?

Visit my NexusFi Trade Journal Reply With Quote
  #20 (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
Very useful. I have noticed that although you request the image to be a jpg file, it is always a bmp file with the extension jpg. I tried changing to png file in oder to get a smaller file, but it still saves very large bmp files.
Is there a way around this ?

In Vista the default save type rom MS Paint is .jpg, it might be .bmp in Windows XP. I can add a couple of lines to force to save as .jpg or .png

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