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

Workaround to Debug with Visual Studio Express Edition

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

    Workaround to Debug with Visual Studio Express Edition

    Hi,

    While VS express edition is missing the ability to "attach to process" it still can be done, thx to this post:


    What to do?
    1) Open Visual Studio.
    2) Create new project (I craeted regular console application), let call it NinjaTraderDebug.
    3) Save the project and close visual studio.
    4) Go to the project directory and open with notepad the NinjaTraderDebug.csproj.user file.
    5) Edit it to look like this (the bold lines is what I added, of course you need to put your path to NinjaTrader.exe).
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
    <StartAction>Program</StartAction>
    <StartProgram>C:\Program Files\NinjaTrader 6.5\bin\NinjaTrader.exe</StartProgram>
    </PropertyGroup>
    </Project>

    6) Close NinjaTrader if it is opened.
    7) Open the ninjatraderDebug project in VisualStudio.
    8) Hit "Play" (F5), this will launch NinjaTrader and will attach to it.
    9) Now do sections 1 and 3 from here:


    It works for me

    Yuval.

    #2
    Thanks for this contribution.
    RayNinjaTrader Customer Service

    Comment


      #3
      After Start Debugging in Visual Studio Express, a new instance of Ninjatrader is spawned. If I try to open Ninjatrader outside VS Express, get error "not allowed to run 2 instances of Ninjatrader". I selected Debug Mode from Ninjatrader instance before opening VS Express. From VS Express' Ninjatrader instance, I connected to my datafeed and selected and ran my strategy from the Strategy Analyzer. I placed a Print statement in my code in the OnBarUpdate() method just for further verification my code is getting executed. Ninjatrader supposedly runs the strategy but I get no feedback from Print statement or see any output from my Drawline calls in my code. I set breakpoints in VS Express but they become inactive after Start Debugging from VS Express. VS Express shows from hovering pointer over breakpoint, "The breakpoint will currently not be hit. No symbols have been loaded for this document." It can't be referring to a symbol in terms of a Ninjatrader instrument/symbol for a chart because I have a chart up in Ninjatrader which is displaying candles. Could it be running the strategy without executing my code? How do I get the breakpoint active?

      Comment


        #4
        I'm not sure I understand you scenario.
        Anyway, you should NOT have 2 ninja instances (see section 6 in my explanation).
        After you hit F5 and Ninja is launched from VS, go to script editor and mark "Debug Mode" and recompile (this will generate the pdb).
        When you set a breakpoint it is OK that you get it "hollowed", it depends whether Ninja had already loaded or not you dll.

        Comment


          #5
          aascotty,

          Unfortunately NT does NOT work with the Express version of VS.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Hi Yuval ,

            The workaround works for VS Express 2008 either (I'm using NT7), but adding
            <PropertyGroup>
            <StartAction>Program</StartAction>
            <StartProgram>C:\Program Files\NinjaTrader 7\bin\NinjaTrader.exe</StartProgram>
            </PropertyGroup>
            should be done in a file :
            NinjaTraderDebug.csproj , not NinjaTraderDebug.csproj.user as you and the blog above state.
            Altering NinjaTraderDebug.csproj.user invalidates the solution.

            At least that's what's work for me.
            Happy debugging.

            Comment


              #7
              Hi,

              I just tried debugging NT 7 Beta 22 with Visual Studio 2010 Express edition yesterday night and it worked perfectly.

              I have just updated the NinjaTraderDebug.csproj (and not NinjaTraderDebug.csproj.user which does not exist) as specified in this thread.

              Have fun,
              Olivier.

              Comment


                #8
                Hello. Thanks for this tip, i will extend it... It's working perfectly even for VS2010 Express. I had combined it with solution based on this template. So when i compile solution, the library with my code is placed to the Custom folder of NT and afterwards the NT is started with this library loaded. Then I can even Pause debugging, make change in code and hitting Continue will recompile my code without restarting NT ! So this way I can use professional development IDE and debugging capabilities without pain Hope this helps somebody too.

                Comment


                  #9
                  Hi FredyC,
                  i tried your example. But i get error messages like this

                  Error 64 'NinjaTrader.Indicator.ADX' does not contain a definition for 'BarsRequired' and no extension method 'BarsRequired' accepting a first argument of type 'NinjaTrader.Indicator.ADX' could be found (are you missing a using directive or an assembly reference?) C:\Users\Ede\Downloads\NT7\Samples\VS_NTSampleProj ect\VS_NTSampleProject\VS_NTSampleProject\Indicato r\@ADX.cs 145 23 VS_NTSampleProject
                  What could be the problem?

                  Thanks
                  Eddy

                  Comment


                    #10
                    Confirming this procedure still works . Debugger works with breakpoints.

                    However, type ahead does not seem to be working for me which makes coding in VS Express much less useful (still good for debugging though). Any ideas on what needs to be changed to get type ahead to work in visual studio express C# 2010? Missing a reference somewhere?

                    Does type ahead work in the full VS version? Thanks,

                    kc

                    Comment


                      #11
                      Link http://www.ninjatrader-support.com/H...l?VisualStudio is not working?
                      Is there an alternative link?
                      Thanks,

                      Comment


                        #12
                        Can you try this one here for 6.5?

                        BertrandNinjaTrader Customer Service

                        Comment


                          #13
                          I don't develop Microsoft software (I'm more a unix guy), so I can't justify purchasing the whole Visual Studio package just to debug a few NinjaScripts. Therefore, I was really glad to find this thread.

                          My NinjaTrader coding has gotten complex enough (with custom classes and all) that I need more than Print() to debug anything, especially because Print() doesn't work inside my own classes. Being a veteran programmer who is unfamiliar with Microsoft development tools, I have to ask: How do I actually debug anything with Visual Studio Express?

                          I've followed the instructions in this thread. I got NT7 to attach to Visual C# Express 2010, compiled MyIndicator with Debug Mode enabled, then in Visual C# I went to File->Open File and found MyIndicator.cs, and loaded it.

                          Then what?

                          I can set a breakpoint in my indicator code, but Visual C# attaches a note to it saying "The breakpoint will not be hit. No symbols have been loaded for this document." And of course, when I reload NinjaScripts from the chart displaying my indicator, it isn't executed in the debugger. Stopping debugging also closes NinjaTrader.

                          Any tips to get me started? What step have I missed? Do I need to create a project for my indicator and make similar modifications to the project files?

                          Thanks.
                          -Alex
                          Last edited by anachronist; 03-02-2012, 05:26 PM.

                          Comment


                            #14
                            You need to hit F5 (compile) everytime to 'load the symbols'.

                            Other thing:
                            IMPORTANT: You need to disable breakpoints in VS when you first start debugging. Otherwise, Market Replay will hang. This is the order: (a) start Market Replay at the desired date/time, (b) set up Break points, (c) Run Market Replay. Then it will stop at the desired date/time and code location.

                            Let me know if you have more questions... I also struggled a bit to get this going but now it works great for me.

                            Comment


                              #15
                              Thanks ds1111. I don't notice anything different.

                              I have two tabs in Visual C#. One is Program.cs, an empty bit of project code described in this thread to attach NinjaTrader. The other tab is my indicator script, call it MyIndicator.cs, which is found in NinjaTrader 7\bin\Custom\Indicator\MyIndicator.cs. I've compiled it in the NT7 editor in Debug Mode. The Program.cs tab contains only this:
                              Code:
                              using System;
                              using System.Collections.Generic;
                              using System.Linq;
                              using System.Text;
                              
                              namespace ConsoleApplication1 {
                                  class Program {
                                      static void Main(string[] args) {
                                      }
                                  }
                              }
                              Do I need to change the namespace or class in this?

                              If I stop debugging, NinjaTrader closes.

                              If I go to the MyIndicator.cs tab and press F5, NinjaTrader starts up again, and it loads my workspace with my chart that displays my indicator.

                              I thought I'd hit a breakpoint if I right-clicked on my chart and selected "Reload NinjaScript." Is replay mode necessary for debugging?

                              Thanks.
                              Alex
                              Last edited by anachronist; 03-02-2012, 05:56 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by firefoxforum12, Yesterday, 08:53 PM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by kmunroe478, Yesterday, 05:39 PM
                              2 responses
                              14 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by kevinenergy, 02-17-2023, 12:42 PM
                              115 responses
                              2,699 views
                              1 like
                              Last Post kevinenergy  
                              Started by prdecast, Today, 06:07 AM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by Christopher_R, Today, 12:29 AM
                              1 response
                              14 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Working...
                              X