AutoHotKey scripts for editing/debugging NT scripts in Visual Studio - NinjaTrader Programming | futures.io
futures io futures trading


AutoHotKey scripts for editing/debugging NT scripts in Visual Studio
Started: by swinger Views / Replies:833 / 5
Last Reply: Attachments:0

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
 
Thread Tools Search this Thread
 

AutoHotKey scripts for editing/debugging NT scripts in Visual Studio

  #1 (permalink)
Elite Member
Raleigh NC/USA
 
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: stocks
 
Posts: 27 since Oct 2014
Thanks: 106 given, 11 received

AutoHotKey scripts for editing/debugging NT scripts in Visual Studio

If you debug ninjascripts in Visual Studio, you know what a pain the repetitive process of launching everything, recompiling the script and attaching VS to the NT process is.

I used AutoHotKey to automate some of this.

First script:
1. launches NT
2. connect to data provider
3. open Ninjascript in NT
4. launch VS
5. open Ninjascript in VS
6. compile script in NT
7. reload all scripts in VS
8. attach VS to NT process (I use the Attach to Anything extension in VS and created a little toolbar; would be nice to access this with a shortcut, but not sure how or if possible)
9. close NT editor

Script is pretty extensively commented, so hopefully it's easy to follow along. I'm pretty new to AHK, and used a lot of pauses and WinWait commands to prevent the script from outrunning itself. It works pretty well now, and I could probably go back and eliminate some of the pauses and WinWait's to make it a touch quicker. If you make any useful mods to this or have any suggestions, post 'em up.

 
Code
#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Window
SendMode Input
#SingleInstance Force
SetTitleMatchMode 2
DetectHiddenWindows On
#WinActivateForce
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1


F3::
Macro1:
Run, "C:\Program Files (x86)\NinjaTrader 7\bin64\NinjaTrader.exe", "C:\Program Files (x86)\NinjaTrader 7\bin64"  ; script to: 1. launch NT;  2. connect to data provider;  3. open Ninjascript in NT;  4. launch VS;  5. open Ninjascript  in VS; 6. compile script in NT;  7. reload all scripts in VS;  8. attach VS to NT process;  9. close NT editor
WinWait, Control Center -
Sleep, 333
WinActivate, Control Center -
Sleep, 333
WinWaitActive, Control Center -
Sleep, 333
Send, {LAlt Down}{f}{LAlt Up}{c}  ; connect to data provider
Send, {k}  ; 'k' is for Kinetick
Sleep, 20
Send, {LAlt Down}{o}{LAlt Up}{e}  ; open existing Ninjascript
Send, {s}  ; 's' is for Strategy 'i' is for Indicator
WinWaitActive, Edit Strategy
Sleep, 333
WinWaitClose, Edit Strategy  ; wait until script manually selected
Sleep, 333
Run, "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe", "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\"  ; launch VS
WinWait, Microsoft Visual Studio
Sleep, 333
WinActivate, Microsoft Visual Studio
Sleep, 333
WinWaitActive, Microsoft Visual Studio
Sleep, 333
Send, {LControl Down}{o}  ; CTRL + o = open file
Send, {LControl Up}
WinWait, Open File
Sleep, 333
WinActivate, Open File
Sleep, 333
WinWaitClose, Open File  ; wait until file manually selected
Sleep, 333
Sleep, 300
WinActivate, Strategy -  ; switch back to Ninjascript editor
Sleep, 333
WinWaitActive, Strategy -  ; would be nice to ensure Ninjascript editor has debugging mode enabled.
Sleep, 333
Send, {F5}  ; compile script in Ninjascript editor
Sleep, 300
Send, {Enter}  ; ok to Ninjascript editor warning
Sleep, 300
WinActivate, Microsoft Visual Studio  ; switch back to VS
Sleep, 333
WinWaitActive, ahk_class #32770
Sleep, 333
Send, {LShift Down}{Y}  ; Shift + y to reload all
Send, {LShift Up}
Sleep, 300
WinActivate, Microsoft Visual Studio
Sleep, 333
WinWaitActive, Microsoft Visual Studio
Sleep, 333
Sleep, 300
Click, 1188, 77 Left, Down  ; accessing Attach to Anything extension's toolbar
Sleep, 300
Click, 1188, 77 Left, Up
Sleep, 500
Send, {Down}{Down}  ; Ninjatrader is the second process in my Attach to Anything toolbar's list
Send, {Enter}
Sleep, 300
WinClose, Strategy -  ; close Ninjascript editor. Don't want it open while editing the same script in VS.
Sleep, 333
Return
If anyone has other useful AHK scripts they use to automate steps when working with VS and NT, or suggestions, feel free to add to this thread.

Reply With Quote
The following 2 users say Thank You to swinger for this post:
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Raleigh NC/USA
 
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: stocks
 
Posts: 27 since Oct 2014
Thanks: 106 given, 11 received


This next AHK script is intended to be used when making changes to your ninjascript while debugging. After saving changes in VS, run this script to stop debugging, open the script in NT editor, compile, reload in VS, attach VS to NT process and close NT editor.

 
Code
F4::
Macro2:
WinActivate, Microsoft Visual Studio  ; script intended to be used after saving changes made to Ninjascript in VS while debugging.  script: 1. stops debugging;  2. manually open script in NT editor;  3. compile script in NT editor;  4. reload all scripts in VS;  5. attach VS to NT process;  6. close NT editor
Sleep, 333
WinWaitActive, Microsoft Visual Studio
Sleep, 333
Send, {LShift Down}{F5}  ; Shift + F5 = stop debugging
Send, {LShift Up}
Sleep, 300
WinActivate, Control Center -
Sleep, 333
WinWaitActive, Control Center -
Sleep, 333
Send, {LAlt Down}{o}{LAlt Up}{e}{s}
WinWaitActive, Edit Strategy
Sleep, 333
WinWaitClose, Edit Strategy
Sleep, 333
Send, {F5}  ; compile script in Ninjascript editor
Sleep, 300
Send, {Enter}  ; ok to Ninjascript editor warning
Sleep, 300
WinActivate, Microsoft Visual Studio
Sleep, 333
WinWaitActive, ahk_class #32770
Sleep, 333
Send, {LShift Down}{Y}  ; Shift + y to reload all
Send, {LShift Up}
WinActivate, Microsoft Visual Studio
Sleep, 333
WinWaitActive, Microsoft Visual Studio
Sleep, 333
Click, 1188, 77 Left, Down  ; accessing Attach to Anything extension's toolbar
Click, 1188, 77 Left, Up
Sleep, 500
Send, {Down}{Down}  ; Ninjatrader is the second process in my Attach to Anything toolbar's list
Send, {Enter}
Sleep, 300
WinClose, Strategy -  ; close Ninjascript editor. Don't want it open while editing the same script in VS.
Sleep, 333
Return

Reply With Quote
The following user says Thank You to swinger for this post:
 
  #4 (permalink)
Elite Member
Raleigh NC/USA
 
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: stocks
 
Posts: 27 since Oct 2014
Thanks: 106 given, 11 received

A little more detail on Attach to Anything ("A2A") as some might find this useful, regardless of whether they are accessing it in a script or manually - either way, it's a lot quicker than Debug > Attach to Process > scroll down to find NT > Attach.

You can grab this extension by going to VS Extension Manager. Search Online Gallery for "Attach to Anything". In A2A's options (can access from either toolbar or Tools > Options > Debugging > A2A), select the the Ninjatrader process and Add. Now in the A2A toolbar, you will have Ninjatrader.exe.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


It would be nice to access this by shortcut (in my AHK script, I access it by mouse pointer), but I'm not sure how, or if it's even possible. If anyone knows how to do this, please let me know, thanks.


Last edited by swinger; January 28th, 2015 at 10:32 AM.
Reply With Quote
The following user says Thank You to swinger for this post:
 
  #5 (permalink)
DabbaDo
Indianapolis/IN
 
Futures Experience: Intermediate
Platform: SC, NT, ToS, my own
Broker/Data: Stage5, InteractiveBrokers
Favorite Futures: ES
 
Posts: 55 since Jan 2013
Thanks: 944 given, 91 received

Visual Studio 2013 - Yet another AutoHotKey script - NT7

Futures Edge on FIO

What value do you place on the webinars on FIO?

 
FWIW, here is a snippet that works on my machine. Both VS2013 and NT7 are assumed to be open. You have installed the ReAttach extension, and you have used it to attach to the NT process. If you hover over the red play button, you'll see that Ctrl+R,Ctrl+1 re-attaches (that is the assumption in the script). Your NT debugging is set to Debug Mode.
Once you have run the script, F4 (from any window, not just VS or NT) will ReAttach to NT, open an indicator, compile it and close the window. Now you can Reload NinjaScript from a chart to hit breakpoints in VS.

 
Code
; This is for NT7
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

SetTitleMatchMode 2 ; partial match

F4::

; This does the attach of an open Visual Studio (2013) to NT7 using the ReAttach extension
WinActivate, Microsoft Visual Studio  
Sleep, 333
WinWaitActive, Microsoft Visual Studio
Sleep, 333
Send, ^r
Sleep, 10
Send,^1  ; look at the ReAttach shortcuts to ensure you're getting the correct NT process (most recently used)

; This does the compile of an indicator (and everything else) in NT
WinActivate, Control Center - ; case specific
Sleep, 333
WinWaitActive, Control Center -
Sleep, 333
Send, {LAlt Down}{o}{LAlt Up}{e}{i}{Down}{Down}{Down}{Down}{Down}!o ; move to some indicator high in the list, then Okay
Sleep, 50
WinActivate, Indicator -
Sleep, 333
WinWaitActive, Indicator -
Sleep, 333
Send, {F5}  ; compile script in Ninjascript editor
Sleep, 300
Send, {Enter}  ; ok to Ninjascript editor warning
Sleep, 1000
Send, {LAlt Down}{F4}{LAlt Up} ; close the indicator edit window
return ; now we are in debug mode. Reload NinjaScript from a chart, or whatever, to debug

Reply With Quote
 
  #6 (permalink)
DabbaDo
Indianapolis/IN
 
Futures Experience: Intermediate
Platform: SC, NT, ToS, my own
Broker/Data: Stage5, InteractiveBrokers
Favorite Futures: ES
 
Posts: 55 since Jan 2013
Thanks: 944 given, 91 received

Technique for debugging from VS F5 without using NS Editor

This is an old thread, and it has helped me.
But this month Brett at NinjaTrader put out a sample project that makes all of this very simple, IMHO.
The link is at: What version of the compiler is NT using? - NinjaTrader Support Forum

In a nutshell:

Quote:
Originally Posted by NinjaTrader_Brett View Post
C# 6.0 came out near the tail end of our development and is actually a little tricky to integrate support for that since the compiler is no longer part of .net framework. You have to use the new roslyn compiler now separately. Furthermore various third party tools we use didn't support it yet so we made the decision to hold off on support for that.

There is a workaround which is developing in Visual Studio to compile a .dll and import it into NinjaTrader. I made this template visual studio file which allows you to do just that. As long as NT is installed in default location you can develop in this visual studio project. Press F5 and it will copy over a DLL to NT to autoload and start NinjaTrader in debug mode. The example uses an AddOn but you could do indicators/strategies/other as well.

-Brett
Brett,

My additional notes:

The NinjaTraderAddon project properties Build Steps has two xcopy commands under Build Steps to copy its dll and pdb files to the proper location, and the NinjaTraderStartupProject project properties Debug has "Start external program" to launch NT8.

Reply With Quote

Reply



futures io > > > > > AutoHotKey scripts for editing/debugging NT scripts in Visual Studio

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Spring Grains Outlook w/Sean Lusk @ Walsh Trading

Elite only

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

April

Process above all else w/Anthony Crudele @ Futures Radio Show

Elite only

Machine Learning - Quantitative Trading w/Martin Froehler @ Quantiacs

Elite only

Market Dynamics w/Peter Davies @ Jigsaw Trading

Elite only

Ask Me Anything w/Patrick Rooney @ Trading Technologies

Apr 18

Ask Me Anything w/FuturesTrader71

Apr 19

Machine Learning w/Kris Longmore

Elite only

Market Analysis w/Dave Forss

Apr 25

Introducing iSystems with Stage 5 Trading

Apr 27
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
AutoHotkey Scripts monpere NinjaTrader 41 October 8th, 2016 08:33 PM
Visual Studio 2012 Express Debugging aguison NinjaTrader Programming 5 July 1st, 2013 12:56 AM
Any NT scripts or tools that display a better DOM w/Level II? forrestang NinjaTrader 11 June 6th, 2012 09:03 AM
Using Visual Studio (Express) w/ NT LostTrader NinjaTrader Programming 3 July 28th, 2010 07:48 PM
Visual Studio 08 NT programming symphys NinjaTrader Programming 5 March 8th, 2010 04:45 AM


All times are GMT -4. The time now is 06:55 AM.

no new posts
Page generated 2017-03-30 in 0.15 seconds with 19 queries on phoenix via your IP 54.211.108.8