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

Unit testing

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

    Unit testing

    Is there a practical way to unit test NinjaScript code (e.g. custom stratgies, indicators, add-ons)?

    Is any one using any harnesses that might work for this?

    #2
    Hello AnotherTrader,

    Thank you for the post.

    This item is likely going be best answered by the community members who have experience with this specific concept as this is not something our support would have direct information on.

    From my knowledge of unit testing, it would likely be possible to access NinjaScript objects from the test. However, in contrast to how unit testing works, it may not be directly possible to recreate accurately what the platform does with the objects you would be testing (indicator, strategy). There are many steps required in correctly instantiating a NinajScript object that happens internally so that portion of this concept would not easily be recreated in a test.

    If any other community members have further information on this topic, I am sure they will post their knowledge here as well.

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

    Comment


      #3
      To continue this thread, I have posted some code on github ...

      https://github.com/Abattia/NinjaTrader8_UnitTests Experiment to devise a means to unit test NinjaScript

      My objective is to write higher quality NinjaScript code by devising a way to use Test Driven Development ( https://en.wikipedia.org/wiki/Test-driven_development ).

      As I outline in the github README.md, I don't think this is possible at present. Tools like MSTest cannot be applied in NinjaScript projects (for perfectly understandable reasons related to keeping the NT proprietary code proprietary!).

      So, the github project is an invitation to anyone out there who might have ideas of how we might devise an alternative that achieves the same objective, i.e. higher quality NinjaScript code.

      Here is the sort of log output the current code produces:



      All contributions and suggestions greatefully received ...

      Comment


        #4
        FYI Updated this: https://github.com/Abattia/NinjaTrader8_UnitTests Experiment to devise a means to unit test NinjaScript

        Comment


          #5
          i like this idea. i will try to use your templates. I also want to store the results of the test in a format that i can compare the results over iteration. will keep posted on this.

          Comment


            #6
            Originally posted by junkone View Post
            i like this idea. i will try to use your templates. I also want to store the results of the test in a format that i can compare the results over iteration. will keep posted on this.
            I and my team currently use this framework in any new custom strategy that we code.

            If you have any ideas on how to develop it further or to extend it, or you would like to contribute to the github repo, please just let me know.

            Comment


              #7
              junkone

              Don't let that guy know, he is trying to steal other people idea to earn money.

              Comment


                #8
                Hi everyone,

                I have used the above "framework" for a bit - It generally works.

                If you want to use Visual Studio with NUnit to test Ninja Strategies or Indicators there is now a step-by-step guide available here:
                A step-by-step guide to implementing TDD Best Practice in NinjaTrader 8 with NUnit and Visual Studio Community Edition.


                HTH
                Frank

                Comment


                  #9
                  Originally posted by AnotherTrader View Post
                  Is there a practical way to unit test NinjaScript code (e.g. custom stratgies, indicators, add-ons)?

                  Is any one using any harnesses that might work for this?
                  Hi everyone! I came across an interesting solution for running unit tests in NinjaTrader 8. It’s called NinjaTraderUnitTesting and provides a testing framework similar to Python’s unittest module. This allows you to write and run unit tests for your NinjaScript code in a simple and easy way. I have been using it in my projects and it has been very helpful in ensuring that my code is working correctly. If you’re interested, you can find more information about NinjaTraderUnitTesting on GitHub.
                  A unit testing framework for NinjaTrader that provides a simple and easy-to-use API for writing and running unit tests for NinjaScript code. - GitHub - samuelcaldas/NinjaTraderUnitTesting: A unit testing framework for NinjaTrader that provides a simple and easy-to-use API for writing and running unit tests for NinjaScript code.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by kulwinder73, Today, 10:31 AM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by RookieTrader, Today, 09:37 AM
                  3 responses
                  15 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by terofs, Yesterday, 04:18 PM
                  1 response
                  24 views
                  0 likes
                  Last Post terofs
                  by terofs
                   
                  Started by CommonWhale, Today, 09:55 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by Gerik, Today, 09:40 AM
                  2 responses
                  8 views
                  0 likes
                  Last Post Gerik
                  by Gerik
                   
                  Working...
                  X