Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Null reference exception in RaiseExecutionUpdate

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

    Null reference exception in RaiseExecutionUpdate

    Hi,
    I am getting unhandled exception when attempting to call CloseStrategy()
    It is not in my code, it happens right after OnExecutionUpdate()
    How do I diagnose the problem?

    2020-11-25 18:21:39:572 *************** unhandled exception trapped ***************
    2020-11-25 18:21:39:572 Exception has been thrown by the target of an invocation.
    2020-11-25 18:21:39:572 Object reference not set to an instance of an object.
    2020-11-25 18:21:39:601 System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
    at NinjaTrader.NinjaScript.StrategyBase.Process(Objec t sender, ExecutionEventArgs executionUpdate)
    at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
    at NinjaTrader.Cbi.Account.RaiseExecutionUpdate(Execu tionEventArgs e)
    at NinjaTrader.Cbi.Account.ExecutionUpdateCallback(In strument instrument, String executionId, Exchange exchange, DateTime time, MarketPosition marketPosition, String orderId, Int32 quantity, Double price, Double commission, Double fee, Boolean isSod, DateTime statementDate, Operation operation)
    at NinjaTrader.Cbi.Simulator.Fill(Int32 maxFillQuantity, Double price)
    at NinjaTrader.Cbi.Simulator.OnMarketData(Object sender, MarketDataEventArgs e)
    at NinjaTrader.Cbi.Simulator.<>c__DisplayClass21_0.<O nTimerSubmitNow>b__0(MarketDataEventArgs e)
    --- End of inner exception stack trace ---
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeIn ternal(Object obj, Object[] parameters, Object[] arguments)
    at System.Delegate.DynamicInvokeImpl(Object[] args)
    at System.Windows.Threading.ExceptionWrapper.Internal RealCall(Delegate callback, Object args, Int32 numArgs)
    at System.Windows.Threading.ExceptionWrapper.TryCatch When(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

    #2
    Hello michaelsh,

    Thank you for your post.

    This error message specifically means that something in your script is returning null.

    To understand why the script is behaving as it is, such as returning a null value for an object, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition in your script along with the time of that bar so you may evaluate which object is returning null. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Below is a link to a forum post that demonstrates using prints to understand behavior and including a link to a video recorded using the Strategy Builder.
    https://ninjatrader.com/support/foru...121#post791121

    Please let me know if I may further assist.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Brandon, thank you for your reply.
      Please examine the call stack I have provided.
      My script, which overrides OnExecutionUpdate(), is executed successfully
      Exception is happening after this call, in a NinjaTrader.NinjaScript.StrategyBase.Process() method

      As I don't have the access source code of the NinjaTrader.NinjaScript.StrategyBase.Process() method, can you suggest what objects of the strategy is it using?

      Comment


        #4
        Hello michaelsh,

        Thank you for your note.

        Please use Visual Studio debugging seen in the help guide link below and add a break point on the line that the exception occurs on. After adding the break point, run your NinjaScript in NinjaTrader and it should stop at your break points and all the debugging tools and information should be available to inspect the current state of the code.

        Visual Studio Debugging - https://ninjatrader.com/support/help..._debugging.htm

        Let us know if you have further questions.
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by sidlercom80, Today, 02:40 AM
        0 responses
        1 view
        0 likes
        Last Post sidlercom80  
        Started by b16_aln, Today, 01:52 AM
        0 responses
        4 views
        0 likes
        Last Post b16_aln
        by b16_aln
         
        Started by junkone, Yesterday, 08:55 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by adaeiqendqw, 01-16-2021, 02:56 AM
        1 response
        15 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by [email protected], Yesterday, 06:10 PM
        5 responses
        16 views
        0 likes
        Last Post NinjaTrader_ChrisSch  
        Working...
        X