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 Irukandji, Today, 05:50 AM
          0 responses
          5 views
          0 likes
          Last Post Irukandji  
          Started by ageeholdings, Today, 05:22 AM
          0 responses
          9 views
          0 likes
          Last Post ageeholdings  
          Started by llanqui, 04-28-2024, 10:32 AM
          2 responses
          20 views
          0 likes
          Last Post llanqui
          by llanqui
           
          Started by DroneBlackCa, Today, 05:17 AM
          0 responses
          6 views
          0 likes
          Last Post DroneBlackCa  
          Started by tradingnasdaqprueba, 04-09-2024, 09:52 AM
          7 responses
          50 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X