NexusFi: Find Your Edge


Home Menu

 





Debug Strategies and Indicators with the MicroSoft CLR Debugger


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Trader.Jon with 1 posts (0 thanks)
    2. looks_two monpere with 1 posts (1 thanks)
    3. looks_3 neilsomi with 1 posts (5 thanks)
    4. looks_4 sam028 with 1 posts (17 thanks)
    1. trending_up 11,646 views
    2. thumb_up 23 thanks given
    3. group 9 followers
    1. forum 6 posts
    2. attach_file 2 attachments




 
Search this Thread

Debug Strategies and Indicators with the MicroSoft CLR Debugger

  #1 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

It's from NT official forum, posted by dbw451 (thx to him).
Very useful when simple debug procedure (Print"..." have failed).

This is describing how to debug strat/indic with CLR debugger (C:\Program Files (x86)\Microsoft.NET\SDK\v2.0\GuiDebug\DbgCLR.exe).

Tip
I didn't see any information in this forum about using Microsoft's CLR Debugger with NinjaTrader. Since NinjaTrader v6.5 is a .Net Framework 2.0 application, strategies and indicators can be debugged using Microsoft's CLR Debugger which included in the free .Net Framework 2.0 SDK. The CLR debugger is a sub-set of the Visual Studio debugger. It is useful because you can set breakpoints, look at variable values, and explore classes.

Now before I go on, let me state that this post is FYI only; I do not have the time to answer questions about the installation or usage of the CLR debugger. However, I think this is important enough information for the NinjaTrader community that I decided to take the time to post.

To setup and use the Microsoft CLR debugger with NinjaTrader:

1. Download and install the .Net Framework v2.0 SDK:

https://www.microsoft.com/downloads/details.aspx?FamilyID=fe6f2099-b7b4-4f47-a244-c96d69c35dec&displaylang=en

2. Run the CLR debugger (the install will setup a link through "All Programs" under your Windows Start button)

3. In NinjaTrader, open an indicator or strategy to debug, right click, and select Debug Mode. Compile the NinjaTrader code. You'll get a message about Debug mode, simply hit Ok to continue.

4. In the CLR Debugger use File->Open->File... and open the .cs source file for the strategy or indicator you compiled in step 3. The default location for an indicator source file is: C:\Documents and Settings\<your username>\My Documents\NinjaTrader 6.5\bin\Custom\Indicator. The strategies are under the same path except ..\Custom\Strategy.

5. In the CLR Debugger under the Debug menu, select "Attach to Process...". Scroll down and highlight NinjaTrader.exe. Press the Attach button. Close the window.

6. In the CLR Debugger, find a good place for a breakpoint in your source file which should already be open from step 4 and press F9 to set a breakpoint. If the breakpoint dot is not solid, go back to NinjaTrader and compile the source file again and then return to the CLR Debugger. The CLR Debugger should recognize that the source file has changed and ask to reload it. Press Yes to All. By this point, the breakpoint should be a solid dot and ready to go.

7. Now use NinjaTrader as you normally would to execute your strategy or indicator. Once the break point in the CLR debugger is hit, execution will stop and you'll have access to the debugging environment.

This is a pretty good and much cheaper alternative than using the full blown Visual Studio for debugging. I hope you find the CLR debugger as useful as I do.

Regards,

David
dbw451


Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Futures True Range Report
The Elite Circle
Deepmoney LLM
Elite Quantitative GenAI/LLM
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
 
  #2 (permalink)
 
qewcool's Avatar
 qewcool 
canada
 
Experience: Intermediate
Platform: Ninjatrader
Posts: 44 since Apr 2010
Thanks Given: 25
Thanks Received: 15

Thanks for this
Is there a comparable procedure for use with VS2008 ?

========================================

Actually found a procedure in the NT help guide for VS2005. Guess should be the same steps for VS2008.

http://ww25.ninjatrader-support.com/HelpGuideV6/helpguide.html?VisualStudio&subid1=20240328-0844-270c-b532-3b999dfee1bb

Reply With Quote
  #3 (permalink)
 
Trader.Jon's Avatar
 Trader.Jon 
Near the BEuTiFULL Horse Shoe
 
Experience: Beginner
Platform: NinjaTrader
Broker: MBTrading Dukascopy ZenFire
Trading: $EURUSD when it is trending
Posts: 473 since Jul 2009
Thanks Given: 401
Thanks Received: 184


Is there a recommendation on how to use CLR in NT7 / Win7 environment ... or WinDBG ??

I am trying the CLR Debugger but cannot get past the error that it cannot automatically select the type of code.

[edit] I did a repair of the SDK install and it is working ... still would appreciate feedback from a person with experience:

The strategy normally only takes a minute to run backtest on the data/dates I am using, but its been 20 minutes since the last entry in the 'modules' of CLR and still have the 'busy' running on NT7 .. sadly no F1 help available in CLR to offer assist .. I have a red circle with a yellow arrow (still) where I selected the breakout point in the debugger ... specifically what should I be seeing?

[edit2] OK, installed VS2008 on trial and at least I managed to get the debugger and NT to exist togeter ... no exception error in the NT log tab yet (2 hours after starting the 1 minute backtest) and zero entries in the VS2008 error list panel ... maybe I'll start a new thread later after I read the dummies book ...

Thanks for any feedback!
Jon

Attached Thumbnails
Click image for larger version

Name:	errorCLR.jpg
Views:	446
Size:	294.3 KB
ID:	26546  
Reply With Quote
  #4 (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


Trader.Jon View Post
Is there a recommendation on how to use CLR in NT7 / Win7 environment ... or WinDBG ??

I am trying the CLR Debugger but cannot get past the error that it cannot automatically select the type of code.

[edit] I did a repair of the SDK install and it is working ... still would appreciate feedback from a person with experience:

The strategy normally only takes a minute to run backtest on the data/dates I am using, but its been 20 minutes since the last entry in the 'modules' of CLR and still have the 'busy' running on NT7 .. sadly no F1 help available in CLR to offer assist .. I have a red circle with a yellow arrow (still) where I selected the breakout point in the debugger ... specifically what should I be seeing?

[edit2] OK, installed VS2008 on trial and at least I managed to get the debugger and NT to exist togeter ... no exception error in the NT log tab yet (2 hours after starting the 1 minute backtest) and zero entries in the VS2008 error list panel ... maybe I'll start a new thread later after I read the dummies book ...

Thanks for any feedback!
Jon

I used the CLR debugger with NT6.5 and now, currently use it with NT7 on Windows Vista with no problems. Did not have to change anything for it to work with NT7.

Reply With Quote
Thanked by:
  #5 (permalink)
 DaFish 
Kitchener, Ontario, Canada
 
Experience: Advanced
Platform: NinjaTrader, Tradestation
Broker: Interactive Brokers
Trading: Stocks
Posts: 6 since Feb 2012
Thanks Given: 2
Thanks Received: 0


monpere View Post
I used the CLR debugger with NT6.5 and now, currently use it with NT7 on Windows Vista with no problems. Did not have to change anything for it to work with NT7.

I have downloaded Windows 7 x64 SDK kit and I don't see any CLR debugger. I figured this was going to be there.

What should I do? Uninstall this and install SDK for .NET 2 ? When I did that, it did install but there was not executable for CLRDebugger

Please advise.

Reply With Quote
  #6 (permalink)
 neilsomi 
Taylorsville
 
Experience: None
Platform: NinjaTrader
Trading: I'm a newbie I don't know yet but futures seem good
Posts: 3 since Mar 2012
Thanks Given: 17
Thanks Received: 6

I just started using SharpDevelop (its free). Its my first post so I can't post links but you can google Sharp Develop.
Here are the steps:

NinjaTrader
* Open up your strategy for editing in NinjaTrader.
* Right click on the edit window and choose Debug Mode
* Compile your strategy, it should have a popup warning you are in Debug Mode
--- Note: Sharp Develop won't hit break points unless your strategy was compiled in Debug Mode. ---

Sharp Develop
* Create a new Solution - File->New Solution->SharpDevelop->Empty Solution
* Add your strategy file (.cs) to it. Right Click on your Solution in the Projects Pane->Add Item
* Attach Sharp Develop to the NinjaTrader Process - Debug->Attach to Process
* Add break points - put the cursor on a line you want a break point and press F7, or click on the column left of the line numbers.

Run your strategy in the Strategy Analyzer and it will stop at the breakpoints you've specified. You can add watches, view variable contents etc.

Hope this helps

~M

Reply With Quote
Thanked by:
  #7 (permalink)
 Trader Jeff 
Chicago, IL United States
 
Experience: Advanced
Platform: Ninja Trader, Trader Work Station, Think or Swim
Broker: Ninja Trader, Interactive Brokers, TD Ameritrade
Trading: ES
Posts: 27 since Nov 2014
Thanks Given: 7
Thanks Received: 10

Hi there,

I am trying to repair the last of a bunch of compile errors on a Slope indicator in order to use it for a strategy. The last few are: ) expected & ) expected.

I realize it could be due to placing a statement vs. expression but I am not sure how to correct it. Any help would be appreciated. https://msdn.microsoft.com/en-us/library/tc5zwdf7.aspx The line is on the error code CS1026.

In the chance anyone can help, I am attaching Line 46 - where the errors are occurring:
Line 46: if (CrossAbove(MASlopeMulti(BackgroundColorType283.BySlope, 3, 3, 1, 1, 255, Color [Red], Color [DarkRed], Color [Black], Color [Orange], 150, Color [Orange], 3, 3, 10, 10, 0, 0, 3, 8, 20, 20, 13, SlopeMA1Type283.SMA, 13, SlopeMA2Type283.None, -15, MALineColorType283.BySlope, MALineDashStyleType283.BySlope, MALineDashStyle283.Solid, MALineDashStyle283.Solid, MALineDashStyle283.Solid, 4, 4, 4, MALineWidthType283.BySlope, MAPriceTypes283.Open, 15, Color [Black], PaintBarTrendType283.RisingFallingOnly, PaintBarType283.BySlope, Color [Red], Color [Transparent], 35, Color [Green], Color [Blue], Color [Black], true, 1, Color [DarkRed], Color [Blue], Color [ForestGreen], DisplaySlopeLocation283.BottomRight, SlopePrecisionType283.None, SLRType283.Fast, SlopeTagText283.Auto;"[Font{"; Name=Arial; Size=13; Units= 3; GdiCharSet=1; GdiVerticalFont=False; 2; 3; 3; 3; 3; 0.7; 0.7; 255; Color [LightGreen]; UserSlopeTextLocation283.Right; 9; 9;SlopeValue; KAMASlowPeriod; 1; {




Thanks,
Jeff

Attached Thumbnails
Click image for larger version

Name:	Recent-2015-02-17_1626.png
Views:	380
Size:	15.9 KB
ID:	175237  
Reply With Quote




Last Updated on February 17, 2015


© 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