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 calling 'OnExecution' - object reference not set to an instance of an object

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

    Error calling 'OnExecution' - object reference not set to an instance of an object

    I'm trying to load a strategy in Market Replay and it gets hung up doing all the calculations before kicking off (the calcs it does to try to determine current strategy position). I get the error trying to call OnExecution in the log.

    The line of code I've isolated is

    Code:
     
    Print("Test1");
    if (EntryOrder1 != null && EntryOrder1.Token == execution.Order.Token)
    {
    Print("Test2");
    [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]))...[/SIZE][/FONT]
    I'm checking for a null reference which is usually the reason for this error.

    Here is the output just prior to the error. Test1 is right before the line of code above, and Print("test2"); is right after the line of code above, but as you can see Test2 does not print.
    Code:
     
    5/7/2009 1:14:27 PM Cancelled pending exit order, since associated position is closed: Order='NT-00002/Replay101' ...
     
    OnOrderUpdate(): 5/7/2009 1:14:27 PM
     
    OnOrderUpdate(): 5/7/2009 1:14:27 PM
     
    OnOrderUpdate(): 5/7/2009 1:14:27 PM
     
    OnExecution(): 5/7/2009 1:14:27 PM
    Test1
    Any ideas? Thanks,

    kc

    #2
    Can you check if execution.Order is null?
    RayNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Ray View Post
      Can you check if execution.Order is null?
      I'll try that, but you would think if OnExecution is being called, then by default, execution.Order.Token should have some value assigned to it.

      Comment


        #4
        The OnExecution may have been triggering off of a different execution. What were the results from your check?
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          The OnExecution may have been triggering off of a different execution. What were the results from your check?

          I put
          Code:
          && execution.Order != null
          in all the places in OnExecution and the error still generates.

          It is getting hung up on the historical data calcs --- almost like there is a historical database problem from 5/7 or something. Any other ideas?

          Comment


            #6
            If you feel there is a database concern, please try resetting your database. Tools->Options->Misc->Reset DB.

            Please in OnExecution() just print the execution directly without accessing any properties.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Josh View Post
              If you feel there is a database concern, please try resetting your database. Tools->Options->Misc->Reset DB.

              Please in OnExecution() just print the execution directly without accessing any properties.
              It probably is just a database concern because when I load on a different chart (i load this strategy typically on Nasdaq index, and if I change to QQQQ (which is generates very close to the same trade results), it works).

              However I just added
              Code:
              Print("OnExecution triggered by " + execution.ToString());
              and here is the output:
              HTML Code:
              OnExecution(): 5/7/2009 1:30:43 PM
              OnExecution triggered by Execution='NT-00003' Instrument='AAPL' Account='Replay101' Name='Exit' Exchange=Default Price=128.603937442173 Quantity=100 Market position=Short Commission=1 Order='NT-00005' Time='5/7/2009 2:13:59 PM'
              Looks like it called OnExecution at 1:30 but is referencing an execution at 2:13. Probably a non-issue and I know how to work-around in the future, just thought I'd share. I don't want to reset my db but that would probably work. Is there a way just to reset one instrument? I already tried reloading historical data from the chart but that didn't seem to fix it.

              Comment


                #8
                Unfortunately not. You could try closing down the market replay connection and open up anew to see if that helps.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  CancelOrder was the culprit

                  Just figured out what was going on. There was a pause in market data for some reason, or rather a large step change in last traded price as opposed to the normal market movement the strategy normally sees. This caused a profit order to be filled. The profit order execution attempts to cancel a StopOrder --- in this case the StopOrder it expected to be active never got set because the price didn't transition through its trigger point (the step change went well through it and the profit order price). So, I'm now checking all potential stop orders to be != null when the Profit Order gets filled, and this appears to have fixed my issue.

                  Now, the question is, why is my NT data lagging what I'm seeing in TWS? I noticed this today and was going to post another thread regarding it. Here is what I'm seeing...

                  In NT's data window on the top left of the control center, I see the bid, bid volume, ask, ask volume, and last volume all updating a few times per second. However, the 'last' price becomes frozen for seconds to sometimes minutes at a time (this is what caused my above issue...nevertheless I needed to fix this in case a true market step change occurs).

                  I visually confirmed in TWS at the very same time that the last price WAS changing here. It was always at or in between the bid and ask. However, in NT, the bid and ask would start moving up or down together and the last price just stays frozen. Once the last price data starts filtering in again, my OnBarUpdate begins running again and then has to react to what it sees as somewhat of a price shock when in reality there was none.

                  Do I need to use OnMarketData? Is this just a market data throttling issue? Seems to me if TWS has the updated last trade then NT should be getting the data too. Thanks,

                  kc

                  Comment


                    #10
                    If NT receives a last update event then it will display it. If not then it will not. What you may want to consider is checking with no strategies or charts open. Just one instrument in the Control Center readout.
                    Josh P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Irukandji, Today, 09:34 AM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by RubenCazorla, Today, 09:07 AM
                    1 response
                    5 views
                    0 likes
                    Last Post RubenCazorla  
                    Started by TraderBCL, Today, 04:38 AM
                    3 responses
                    25 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by WeyldFalcon, 08-07-2020, 06:13 AM
                    11 responses
                    1,423 views
                    0 likes
                    Last Post jculp
                    by jculp
                     
                    Started by BarzTrading, Today, 07:25 AM
                    2 responses
                    29 views
                    1 like
                    Last Post BarzTrading  
                    Working...
                    X