Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Optimization. 'Instrument.' -> Object reference not set to an instance of an object.

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

    Optimization. 'Instrument.' -> Object reference not set to an instance of an object.

    Hi,

    So, I'm trying to add a 'HeikenAshi' DS using 'AddHeikenAshi()' function. Everything works OK in 'Kinetick', 'Playback' and 'StrategyAnalyzer'. However, it doesn't work in Optimizer. Accessing to 'Instrument' returns 'Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.'. Why? What the issue? How can I solve it?
    Here is the exact code:

    Code:
    else if (State == State.Configure){
        IncludeTradeHistoryInBacktest    = true;
        AddDataSeries(BarsPeriodType.Tick,1);
        AddHeikenAshi(
                        Instrument.FullName,
                        GetBarsPeriodType(pmDsType_DsPeriodType),
                        pmDsType_DsPeriod,
                        BarsPeriod.MarketDataType
        );
        AddDataSeries(
                        GetBarsPeriodType(pmDsType_DsPeriodType),
                        pmDsType_DsPeriod
        );
    }
    ​​

    #2
    Hello webus,

    This is violating the rules of AdDataSeries() (or any other add series method).

    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 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."


    You must hard code the values used in AddDataSeries() and AddHeikenAshi() and you cannot use variables.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Instead of putting Instrument.FullName there, try null.
      Bruce DeVault
      QuantKey Trading Vendor Services
      NinjaTrader Ecosystem Vendor - QuantKey

      Comment


        #4
        Hello,

        null can be used for the instrument, which will use the primary instrument.

        "Tips
        4. For the instrument name parameter null could be passed in, resulting in the primary data series instrument being used."


        However, the pmDsType_DsPeriodType and pmDsType_DsPeriod will have to be removed and hard coded values used instead.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        56 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