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

Analyzer

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

    Analyzer

    I have a strategy that I runn successfully in playback mode, but when I run it through the strategy analyzer I get this message: "Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.". Any thoughts? thanks

    #2
    Hello pman777,
    Thanks for your post.

    Can you post your OnStateChange() method here?
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = @"Enter the description for your new custom Indicator here.";
      Name = "MyNT8RangeBreakoutV2";
      Calculate = Calculate.OnEachTick;
      IsOverlay = true;
      DisplayInDataBox = true;
      DrawOnPricePanel = true;
      ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
      BandOpacity = 3;

      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.AllEntries;
      IsExitOnSessionCloseStrategy = true;
      ExitOnSessionCloseSeconds = 30;
      IsFillLimitOnTouch = false;
      TraceOrders = true;
      BarsRequiredToTrade = 10;
      IsInstantiatedOnEachOptimizationIteration = false; // Disable this property for performance gains in Strategy Analyzer optimizations
      IsUnmanaged = false;
      OrderFillResolution = OrderFillResolution.Standard;
      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
      Slippage = 0;
      StartBehavior = StartBehavior.WaitUntilFlat;
      TimeInForce = TimeInForce.Gtc;
      RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;

      ClearOutputWindow();
      }
      else if (State == State.Configure)
      {
      AddDataSeries(BarsPeriodType.Minute, 1); // BarsInProgress 1 ... we use this as a '1 min timer' so that the OnBarUpdate function ... acts like a timer.
      baseLine = new Series<double>(this, MaximumBarsLookBack.Infinite);
      SetStopLoss(CalculationMode.Ticks, initialStopLevel);
      // SetProfitTarget(CalculationMode.Ticks, 400*TickSize);
      }
      else if (State==State.DataLoaded)
      {
      instName= Instrument.MasterInstrument.Name;
      sessionTxtwithSpacers = sessionTxt;
      DirectoryInfo dir = new DirectoryInfo(NinjaTrader.Core.Globals.InstallDir + "sounds");
      soundFileDir = dir.ToString()+"\\";
      firstPasses = true;

      if (runProgram)
      {
      if (Account.Name != "Sim101" && Account.Name != "Replay101" && Account.Name != "Playback101")
      chartBackroundNoTrade = liveColor;
      else
      chartBackroundNoTrade = originalColor;
      ChartControl.Properties.ChartBackground = chartBackroundNoTrade;
      }
      }

      Comment


        #4
        I believe this is happening because of your 'runProgram' if condition. Are you able to run the strategy when that is commented out?

        Help Guide - Debugging your NinjaScript code
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          OK ... so that suggestion cleared up the error. Thank you! But know another issue has arisen. I ran the strategy for the same time period and for the same parameters as I ran in playback mode ... but received very different results. I checked time and time again to make sure all the settings are the same, but I'm clueless why the results are so different. Is there any place you can direct me to that may help me sort this out? Thanks in advance.

          Comment


            #6
            Hello pman777,

            Thanks for the reply.

            Just to confirm, you are running the strategy in Playback mode, and then you are running the strategy through the Strategy Analyzer and comparing the results?

            If this is the case, and you are seeing different results, it is likely because you need to turn on Tick Replay in the strategy analyzer, this will process the data as it came in instead of on the close of every bar.

            I look forward to assisting further.
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by haas88, 03-21-2024, 02:22 AM
            18 responses
            208 views
            0 likes
            Last Post haas88
            by haas88
             
            Started by Board game geek, Today, 02:20 AM
            0 responses
            6 views
            0 likes
            Last Post Board game geek  
            Started by knighty6508, Today, 01:20 AM
            2 responses
            15 views
            0 likes
            Last Post knighty6508  
            Started by franatas, Today, 01:53 AM
            0 responses
            5 views
            0 likes
            Last Post franatas  
            Started by knighty6508, Today, 01:17 AM
            0 responses
            10 views
            0 likes
            Last Post knighty6508  
            Working...
            X