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

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 alifarahani, Today, 09:40 AM
        6 responses
        36 views
        0 likes
        Last Post alifarahani  
        Started by Waxavi, Today, 02:10 AM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by Kaledus, Today, 01:29 PM
        5 responses
        14 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Waxavi, Today, 02:00 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by gentlebenthebear, Today, 01:30 AM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X