Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

'Object reference not set to an instance of an object' error in NT7R1 but not in B20

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

    'Object reference not set to an instance of an object' error in NT7R1 but not in B20

    Greetings,

    I have spent the better part of this morning try to isolate an error in the log tab of NT7R1

    [[ Error in calling 'OnExecution' method of strategy XXXX 'Object reference not set to an instance of an object' ]] ..

    IS VERY strange as the error shows up in some timeframes I am optimizing but when I page through different time spans Nov2009 - Oct2010 sometimes it appears and sometimes not _without_ any changes in the paramater settings or setting for the PH Genetic.

    This happens with two different desktops running NT7R1 ... when I copy the strategy and indicators and saved .xml for the strategy template (to a VM also running NT7), B20 runs the strategy without any problems, regardless of timespan chosen.

    I am restoring a B20 image to one desktop to see if there is consistency of not getting any errors. I will also be exporting the historical data from the NT7R1 to maintain same basics, and importing that into the B20 ... strategy was developed on the NT7R1, and compiles without problems, there are no special drawing boxes or funny code, so I am wondering what possibly is happening that it has errors in NT7R1 and not in B20?

    Jon

    #2
    Jon, would you mind us testing your strategy with your settings in the SA on our R1 here to attempt reproducing?

    If you could contact us at support at ninjatrader dot com that would be great.

    Thanks,
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Bertrand,

      I will do that ... I am using $EURUSD exclusively ... do you want the data I am testing against?

      Jon

      Comment


        #4
        Thanks Jon, yes that would be great to have the exact same testing base. If the email is getting too big, please use a file sharing service like Filexpressit to upload it.

        Thanks,
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Bertrand,

          It looks like the issue has more to do with corrupted hard disk than software. Thanks for the offer of asist and I will email if issue isnt resolved.

          Jon

          Comment


            #6
            I see this null object exception too. I believe it is caused by the final execution the Optimizer makes to get flat at the end of all the available data. Something about this execution might be screwy, as any strategy that tests things inside OnExecution gets randomly crashed.
            The error never happens on a chart.
            Cheers,
            saltminer

            Comment


              #7
              saltminer, are you checking for the objects being null in OnExecution?
              BertrandNinjaTrader Customer Service

              Comment


                #8
                On a different job a month or so ago I wrote code to check every last thing I could think of for null. Code is below. Despite this, null exceptions were still randomly created.I had to give up trying to test with the Genetic Optimiser.
                The strategy worked fine on charts.

                Code:
                protected override void OnExecution(IExecution execution) 
                        { 
                            if (execution == null || execution.Name == null || execution.Name == "Exit On Close")
                                return;
                            
                            if (execution.Name == "Stop loss" && Position != null && Position.MarketPosition != null &&
                                Position.MarketPosition == MarketPosition.Flat && PyramidOrder != null)
                            {
                                Print("Cancelling pyramid order (if necessary)");
                                CancelOrder(PyramidOrder);
                            }
                            if (Position != null && Position.MarketPosition != null &&
                                PyramidOrder != null && 
                                PyramidOrder.Token != null &&
                                PyramidOrder.StopPrice != null &&
                                PyramidOrder.OrderState != null &&
                                PyramidOrder.Token == execution.Order.Token && PyramidOrder.OrderState == OrderState.Filled
                                && PyramidMaxCount >= PyramidCount) 
                            {
                                // looks like our pyramid order filled, so place a new order further out
                                if (Position.MarketPosition == MarketPosition.Long)
                                    PyramidOrder = EnterLongStop(0,true,PyramidPositionSize,PyramidOrder.StopPrice+(PyramidPipDistance*TickSize),"P"+PyramidCount.ToString());
                                else if (Position.MarketPosition == MarketPosition.Short)
                                    PyramidOrder = EnterShortStop(0,true,PyramidPositionSize,PyramidOrder.StopPrice-(PyramidPipDistance*TickSize),"P"+PyramidCount.ToString());
                                PyramidCount++;
                            }
                
                        }
                Cheers,
                saltminer

                Comment


                  #9
                  saltminer,

                  I suggest using a try-catch block over various segments in your code and that will trap wherever the issue is stemming from.
                  Josh P.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by CortexZenUSA, Today, 12:53 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post CortexZenUSA  
                  Started by CortexZenUSA, Today, 12:46 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post CortexZenUSA  
                  Started by usazencortex, Today, 12:43 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post usazencortex  
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  168 responses
                  2,266 views
                  0 likes
                  Last Post sidlercom80  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  3 responses
                  13 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Working...
                  X