Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unit Test

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

    Unit Test

    Hi,

    I've seen a post about unit testing dating back to 2008. Has anything changed on this front? I would like to write a unit test for a custom strategy that uses a strategy object internally. Is there a way to mock a strategy object, does it implement a interface? I noticed a lot of objects passed are using interfaces (IExecution, IOrder, etc). Is there a sample out there on how to do this?

    Thanks.

    #2
    I thought about using the UserDefinedMethods file and make each strategy implement an IStrategy interface that I wrote that would contain the methods I need. Unfortunately I hit a wall mocking Strategy.Position which returns a Position object rather than IPosition, so I can't mock Strategy's Position property. The Position class won't let me override GetProfitLoss (it's not virtual) so inheriting from Position won't work either.

    Please let me know if there's an easier way or if I'm missing something. Thanks.

    Comment


      #3
      I've reviewed the old thread you refer to and unfortunately I'm not aware of changes in this regard - perhaps those reference samples can help you further -



      The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()

      Comment


        #4
        It would be of great help not only exposing classes a strategy or an indicator must derive from, but exposing [abstract] classes implementing an interface. Every public class withing Ninja should expose its public functionality via implementing an interface. It would be best to separate the definition of these classes in an dedicated assembly eg. "NinjaTrader.Interfaces". This way one could have both - just deriving and inheriting a base implementation - or just implementing an interface and linking in the environment by being found from ninja via reflection searching for classes implementing the interface.
        It would also be extremly wothfull if one could access the Bar data / replay data within a unit-test, so one could run the test against known data checking for the expected outcome!

        Is there any chance to do this, any plan to have an architecture being a bit more of an application development kit - being more state of the art?

        Comment


          #5
          Thanks for your suggestions and input CSharpCoder - supported would be what we documented via the NinjaScript reference in the Help Guide or our samples in the educational section here on the forums - we'll add your request for more granularity to our feedback list.

          Thanks

          Comment


            #6
            Just resurrecting and old topic regarding unit testing.
            Has anything been done in this direction since 2010?

            Comment


              #7
              Hello,

              We are reworking the indicator bases in the next major release, however it's too early for us to confirm what will be changed. Please check back closer to the beta release of the next major release and we'll know more.
              MatthewNinjaTrader Product Management

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              637 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              366 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              107 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              569 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              571 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X