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

Instrument object is null during Strategy Optimization

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

    Instrument object is null during Strategy Optimization

    I started getting this error all of a sudden on the "Instrument" object and it's keeps me from being able to perform optimizations.

    System.NullReferenceException: 'Object reference not set to an instance of an object.'

    Code:
    else if (State == State.Configure)
    {
    
    UnitsCalculation = (Instrument.MasterInstrument.InstrumentType == InstrumentType.Forex)
    ? UnitsCalculationType.Pips
    : UnitsCalculationType.Ticks;
    
    ...
    }
    Click image for larger version  Name:	Capture.PNG Views:	0 Size:	60.8 KB ID:	1181184

    This code is not new, and has worked with optimizations in the past. Is there some way to see a more detailed output of what is going on?

    The problem must be elsewhere in an extremely large code base.

    Back tests run fine, this only occurs during optimizations.

    Thanks
    Last edited by bojim; 12-10-2021, 07:11 AM.

    #2
    Hello bojim,

    Thanks for your post.

    Dynamically adding data is not fully supported. Instrument is not guaranteed to be available in State.Configure, and this specifically will not work with optimizations.

    Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner.


    Please let us know if there is anything else we can do to help.
    JimNinjaTrader Customer Service

    Comment


      #3
      Is there a way to safely determine the Instrument type or tick size during optimizations ?

      Thanks!


      Comment


        #4
        Hello bojin,

        Yes, data will be available in State.DataLoaded, so you may check the Instrument object then.

        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by gbourque, Today, 06:39 AM
        2 responses
        14 views
        0 likes
        Last Post gbourque  
        Started by rexsole, Today, 08:39 AM
        0 responses
        4 views
        0 likes
        Last Post rexsole
        by rexsole
         
        Started by trilliantrader, Yesterday, 03:01 PM
        3 responses
        30 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by cmtjoancolmenero, Yesterday, 03:58 PM
        4 responses
        26 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Brevo, Today, 01:45 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X