Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Attempting TDD with NT8

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

    Attempting TDD with NT8

    Hi guys,

    I know this is not officially supported but I am tryihg to apply Test Driven Development to NT strategies and indicators.

    I've managed to set up my project in Visual Studio 2017 and add all the necessary references to NT to my test project so everything builds fine with no errors.

    e.g. inside the body of my test class, this builds fine;

    Code:
    var obj = new MyCustomIndicator();
    However, when I come to actually run the tests, I get the following error;

    Code:
    Message: Test method testMyCustomIndicator.UnitTest1.TestMethod1 threw exception:
    System.TypeInitializationException: The type initializer for '<Module>' threw an exception. ---> System.ArgumentNullException: Value cannot be null.
    Parameter name: ptr
    I'm guessing this is because when an NT Strategy or Indicator is run, a whole lot of initialization code is run too before the Strategy is instantiated, something which doesn't take place with my simple instantiation statement.

    My question to you is this - is there any way of instantiating an NT Strategy or Indicator from outside? If so, what are the additional setup calls I need to make?

    many thanks

    EDIT:

    I see this issue has been raised before so I am not optimistic re: a solution.

    Last edited by trader_rick; 11-26-2018, 09:59 AM.

    #2
    Hello trader_rick,

    Thank you for the post.

    You are correct, there is a lot of internal handling happening here to instantiate the object correctly. The state system for the script is run along with base properties being populated. This happens with all NinjaScript types and is not necessarily something we could advise how to recreate as that part is internal code. Some types are more simple (import types) than others and you may be able to manually run it through its states using its SetState method but that is not something I could suggest for strategy specifically. I am afraid I won't be able to be much help here other than confirming your suspicions surrounding this question.

    I am unsure if any other forum members have had luck in this area with strategies but if they have I am sure they will post here.

    I do see we have had another request for adding in support for unit testing in the past so I will add you to that feature request as well: SFT-2793

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      OK Jesse, thanks.

      In the meantime, I think I've come up with a workaround. I want to create a dummy instrument which I will associate with test data. Creating the instrument seems straightforward enough from Tools/Instruments/Add. Generating test data is also not a problem. But please could you talk me through how I would associate my new dummy ticker with the data and get my NT strategy to read this in and run on it?

      thanks

      Comment


        #4
        Hello trader_rick,

        If you create a test data set, you could import that using the historical data import tool. You can find directions on how to use this tool along with the formats it supports in the help guide here: https://ninjatrader.com/support/help.../importing.htm

        After creating a new instrument, you would need to create the test data and name the file per the guidelines in the helpguide. For example, importing data for a stock would use the name MSFT.Last.txt.

        The various formats are listed in the linked page, you would output the test data into that format and then the platform could import it for the custom instrument.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks Jesse, However, now I have another issue.

          Is there a limit on exporting historical data?

          I'm using the ES ##-## series as my test data which I'm going to rename with my new test ticker. However, although I can retrieve historical data for this ticker within a chart well prior to what I need, there seems to be around a 6 month cutoff for the start of the data when I export it from Tools/Historical Data/Export, although no such warning is given. You'll only notice it when you go to examine the data.

          EDIT:

          Please ignore - I didn't realize I needed to manually download the data first within the Historical Data window before exporting it.
          Last edited by trader_rick; 11-26-2018, 01:19 PM.

          Comment


            #6
            Hi, I have opened another thread on Unit Testing and TDD. https://ninjatrader.com/support/foru...6-unit-testing

            Did you get any further with this?

            Comment


              #7
              Hello AnotherTrader,

              Thank you for updating the post that you had solved the question.

              Regarding the other thread, unit testing is not something our support would be able to assist with as there is currently no specification for this in NinjaScript. I wouldn't have anything additional that I could add to that post which could be helpful at this point, this is a subject you would need to explore further on your own if this is something you need to use with your development. We do have a feature request for adding in unit test support (SFT-2793) which I have added a vote for.

              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Hi There,

                I have written a guide on how to approach TDD with NUnit with NinjaTrader:


                Hope this helps, feedback welcome!
                Frank

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by DeskTroll, Today, 12:09 PM
                3 responses
                22 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by Pabulon, 12-02-2024, 03:42 PM
                14 responses
                90 views
                0 likes
                Last Post Pabulon
                by Pabulon
                 
                Started by tfa2806trader, Today, 12:04 PM
                10 responses
                25 views
                0 likes
                Last Post tfa2806trader  
                Started by trdninstyle, 11-26-2024, 12:23 PM
                62 responses
                186 views
                0 likes
                Last Post trdninstyle  
                Started by lorien, 08-08-2021, 07:33 AM
                12 responses
                721 views
                0 likes
                Last Post AndyM871  
                Working...
                X