Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Instrument is null when running Strategy Analyzer Optimizer

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

    Instrument is null when running Strategy Analyzer Optimizer

    Strategies that load a supplemental data series.can not be run in the Strategy Analyzer optimizer. The problem only occurs with the overload of the AddDataSeries method that accepts a session template string name as a parameter.

    For example ( within the OnStateChange() method ):

    Code:
    	else if (State == State.Configure)
    			{
                AddDataSeries(Instrument.FullName, new BarsPeriod { BarsPeriodType = BarsPeriodType.Range, Value = 1 }, "CME US Index Futures RTH");
    To demonstrate this I attached a modified version of the SampleMultiTimeFrame strategy. I added the above line of code as well as a property to expose to the SA so that you can run the optimizer.

    When you run the attached strategy you will see the output window:

    Strategy 'Sample multi-timeframe': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.


    I checked in the VS debugger and verified there that it's the Instrument property of StrategyBase that is null.
    Attached Files

    #2
    Hello Brillo,

    It is expected and documented in the help guide that it is not possible to dynamically add data series when optimizing. All secondary series must be hard coded as all data is downloaded for all optimizations before the optimizations begin.

    From the help guide:
    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 into 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.

    AddDataSeries() - http://ninjatrader.com/support/helpG...dataseries.htm

    You could instead do a BarsRequest..
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    55 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    132 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X