Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error when backtesting but not market replay

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

    Error when backtesting but not market replay

    I've always developed my strategies in market replay.

    I'm trying to mess around with the backtest feature in order to learn it.

    In the strategy analyzer I've selected the same strategy that works fine in market replay but in this case it gives: " Error on calling 'OnStateChange' method: Object reference not set to an instance of an object. "

    While trying to debug this, the final print happens right before the following code:

    Code:
    if(State == State.DataLoaded)
    {
         Print("136");
         myHA = HeikenAshi8();
         AddChartIndicator (myHA);
    }
    "136" is never printed.

    I'm new to the strategy analyzer so I'm not sure how much I'd need to modify my code to get it to work here. What could be stopping a strategy from running in strategy analyzer when it works just fine in real life and also just fine in market replay?

    #2
    Hello WalterSkinner,

    If the 136 is not appearing, then something is causing an error before this. Something perhaps in State.Configure or State.SetDefaults?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello WalterSkinner,

      If the 136 is not appearing, then something is causing an error before this. Something perhaps in State.Configure or State.SetDefaults?

      I just noticed that the name of a different strategy is showing up in the output window before the error.

      I removed that strategy by right clicking on the strategy name in the ninjascript explorer (in the editor) and selecting "remove".

      After doing this the error went away.

      Now it looks like the code runs without error but only runs a couple of times with no trades (set to calculate on bar close). Could this be a data issue?

      I have complete market replay data for the period on which I'm trying to run this backtest, but I don't see a way to control the data used from the settings menu in the analyzer.

      Comment


        #4
        Hello WalterSkinner,

        To understand why a strategy is either placing or not placing trades use Print to debug the code.

        Outside of the conditions print the time of the bar, print all values used in the conditions.

        Save the output to a text file and I will be happy to assist with analyzing the output.

        Below is a link to a forum post that demonstrates using Print() to understand behavior.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by WalterSkinner View Post


          I just noticed that the name of a different strategy is showing up in the output window before the error.

          I removed that strategy by right clicking on the strategy name in the ninjascript explorer (in the editor) and selecting "remove".

          After doing this the error went away.

          Now it looks like the code runs without error but only runs a couple of times with no trades (set to calculate on bar close). Could this be a data issue?

          I have complete market replay data for the period on which I'm trying to run this backtest, but I don't see a way to control the data used from the settings menu in the analyzer.
          I had this that was jamming me up that I needed to comment out:

          Code:
          // if(State==State.Historical)
          // return;

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          52 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          70 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          48 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X