Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Object reference not set to an instance of an object.

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

    Object reference not set to an instance of an object.

    Hello,

    In my strategy, I tried to add a second data series, and the strategy returned an error: "Error on calling 'OnStateChange' method: Object reference not set to an instance of an object."
    Please advise what did I do wrong? Is it because my second data series time period is larger than the primary? My chart has only the primary data series displayed.

    else if (State == State.Configure)
    {

    AddDataSeries(Data.BarsPeriodType.Tick, 1);

    // Add daily VIX data series
    AddDataSeries("^VIX", BarsPeriodType.Minute, 1);
    }

    Best,

    Billy​

    #2
    Hello Billy​,

    Are you 100% certain that code is causing the issue?

    Have you created a new test script and added only that code and ensured the reduced test script with only that code is able to reproduce?

    I'm testing and I am not able to reproduce.

    Can you provide an export of the reduced test script that has only the code you posted in post # 1?

    To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...-us/export.htm

    Once exported, please attach the file as an attachment to your reply.​
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Thank you for your response, turns out it was something else. I was accessing Time[0] before the DataLoaded state, I have fixed the problem.

      Best,

      Billy

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      47 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      23 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      51 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X