Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Debug Strategies and Indicators with the MicroSoft CLR Debugger

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Debug Strategies and Indicators with the MicroSoft CLR Debugger

    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:



    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

    #2
    Thanks David,

    Do you know like to debug types ? The types file is in ...\NinjaTrader 6.5\bin\Custom\Types\@BarsTypes.cs.

    Sometimes when the code crash the debugging stops inside @BarsTypes.cs. However I don't get stop the running with a breakpoint in @BarsTypes.cs.

    Regards.

    Comment


      #3
      cls71,

      I've never looked at BarTypes.cs, but I doubt that code is what is causing your exception. When you first start using the CLR debugger, it may find exceptions that may have been there for quite some time but never trapped. Whenever I get an unexplained exception from somewhere within Ninja, I assume its an effect, not the cause. I always assume my code is doing something wrong that caused Ninja to throw an exception. All I can suggest is to look at the stack trace in the CLR debugger and determine what code of yours is calling the Ninja method that's throwing the exception. That may give you a clue as to what could be causing the problem. Sometimes you just have to simplify your code to a state without any exceptions and then layer in the complexity until you can isolate the logic that's causing the exception.

      Regards,

      David
      dbw451

      Comment


        #4
        Thanks David,
        but I need debug the @BarsType.cs file because I am developing a custom type based in bid-ask (like marketdelta.com) and I need understand perfectly how this code works.

        Regards

        Comment


          #5
          thank you david,

          works like a charm.

          Whenever I can help you, please post your question

          andreas

          Comment


            #6
            Excellent andreas. I'm glad to know the CLR Debugger setup instructions worked for you.

            Regards,

            David
            dbw451

            Comment


              #7
              does it offer any features that the VS debugger does not offer. apart from fact that its cheaper

              Comment


                #8
                It's exactly the opposite, Visual Studio offers many more features than the CLR Debugger. The CLR Debugger is a debugger for common library runtime applications only (i.e. .Net applications) where VS is a full feature development environment that can build and debug many types of applications. The CLR Debugger is a small sub-set of the Visual Studio debugger; but it's free and works with NT where VS is $500+ (unless you qualify for a student license). The free Express versions of VS do not have "attach to process" functionality so I'm not sure if there is a way it can be used to debug NT.

                Regards,

                David
                dbw451

                Comment


                  #9
                  Hi, I'm running Vista Premium 64 and downloaded .NET SDK 4.0 . I couldn't find CLR but was able to run the MDE (Microsoft Development Environment). I looked at the processes and couldn't find any to attach to. Can someone help me with this? I would really like to be able to use a debugger with NinjaTrader. Thanks!

                  Comment


                    #10
                    I've been out of .Net development for a while and have not used the .Net 4.0 framework. Apparantly the CLR debugger stopped shipping with VS 2008. There is now something called WinDBG which can be used with SOS.DLL to debug .NET code. I found this presentation which might help you figure out a debugging approach:

                    http://tinyurl.com/2djkzzq

                    Regards,

                    David
                    dbw451

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by rocketman7, Today, 02:12 AM
                    5 responses
                    23 views
                    0 likes
                    Last Post rocketman7  
                    Started by trilliantrader, 04-18-2024, 08:16 AM
                    7 responses
                    28 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by samish18, 04-17-2024, 08:57 AM
                    17 responses
                    66 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by briansaul, Today, 05:31 AM
                    1 response
                    15 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by PaulMohn, Today, 03:49 AM
                    1 response
                    12 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Working...
                    X