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 tests using Visual Studio

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

    Unit tests using Visual Studio

    I am trying to write unit tests for my indicators and strategies. For this, I have created a new Test project in Visual Studio and added the following two references: NinjaTrader.Core and WilsonORMapper.

    In order to use predictable data to test with, I am attempting to create a Bars class and populate it with bars. Here is a snippet of my code:

    Code:
            public static Bars MakeChart(string[] matrix)
            {
                DateTime today = DateTime.Today;
                Period period;
                MasterInstrument mi;
                Instrument instrument;
                Bars bars;
    
                period = new Period(PeriodType.Day, 1, MarketDataType.LastClose);
                mi = new MasterInstrument("TST", InstrumentType.Future);
                instrument = new Instrument(mi, Exchange.Amex, today.AddYears(1), 4, Right.Call);
                bars = new Bars(instrument, period, today, today.AddDays(matrix.Length), true, true);
    
                ...
           }
    The problem is that this code compiles well, but when run, immediately crashes with the following error:

    Code:
    A first chance exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
    A first chance exception of type 'System.TypeInitializationException' occurred in ConsoleApplication1.exe
    An unhandled exception of type 'System.TypeInitializationException' occurred in ConsoleApplication1.exe
    Additional information: The type initializer for '<Module>' threw an exception.
    I've narrowed this problem down to the declaration of any of the NinjaTrader classes, e.g. Period, MasterInstrument or any other. The mere declaration of the variable causes the crash, so it doesn't even get to the initialization of it.

    Is there some kind of a mandatory initialization that I have to include in order to be able to use any components from NinjaTrader.Core, outside of the NinjaTrader editor?

    I am open to any dirty hacks any workarounds.

    Thanks.

    #2
    Hello xsgex,

    Thank you for your post.

    This would be outside the scope of support we can provide here. However, one of our forum members may have information on what you are attempting to do here.

    Please let me know if you have any questions that I may answer.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by rtwave, Today, 01:49 PM
    0 responses
    8 views
    0 likes
    Last Post rtwave
    by rtwave
     
    Started by papaoutai, Today, 08:56 AM
    0 responses
    22 views
    0 likes
    Last Post papaoutai  
    Started by jdspwe, Today, 05:22 AM
    0 responses
    13 views
    0 likes
    Last Post jdspwe
    by jdspwe
     
    Started by JeremuFemstu, Today, 04:49 AM
    0 responses
    16 views
    0 likes
    Last Post JeremuFemstu  
    Started by pjsmith, Today, 04:11 AM
    1 response
    22 views
    0 likes
    Last Post Green Lobster CBD  
    Working...
    X