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

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 marco231, Yesterday, 11:32 PM
          1 response
          4 views
          0 likes
          Last Post marco231  
          Started by sofortune, Yesterday, 10:55 PM
          0 responses
          3 views
          0 likes
          Last Post sofortune  
          Started by sofortune, Yesterday, 10:19 PM
          0 responses
          9 views
          0 likes
          Last Post sofortune  
          Started by sofortune, Yesterday, 10:10 PM
          0 responses
          7 views
          0 likes
          Last Post sofortune  
          Started by sofortune, Yesterday, 09:49 PM
          0 responses
          4 views
          0 likes
          Last Post sofortune  
          Working...
          X