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 help : .<OnBarUpdate>d__49.MoveNext()

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

    Error help : .<OnBarUpdate>d__49.MoveNext()

    Hello,

    I have an error in some custom code that is proving difficult to locate. I would appreciate it if someone might be able to shed any light on what exactly, '.<OnBarUpdate>d__49.MoveNext()' is likely to be related to so I can debug further.

    The issue I have is that this ONLY ever occurs when Ninjatrader is starting up. Never at any time when running. It produces an error thus, from the trace log

    2022-05-17 18:09:01:203 *************** unhandled exception trapped ***************
    2022-05-17 18:09:01:203 Object reference not set to an instance of an object.
    2022-05-17 18:09:01:203 System.NullReferenceException: Object reference not set to an instance of an object.
    at NinjaTrader.NinjaScript.Indicators.mycustomcode. <OnBarUpdate>d__49.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatch Info.Throw()
    at System.Threading.ExecutionContext.RunInternal(Exec utionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionCon text executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
    at System.Threading.QueueUserWorkItemCallback.System. Threading.IThreadPoolWorkItem.ExecuteWorkItem()
    at System.Threading.ThreadPoolWorkQueue.Dispatch()
    2022-05-17 18:09:01:239 ERROR: Indicator '': Error on calling 'OnBarUpdate' method on bar 886: Object reference not set to an instance of an object.


    and crashes out completely. There is never any chance to debug, even with visual studio. This will happen maybe 2/3 times in a row when starting NT8 (latest build and earlier) on occasion, then, just go away and not happen again for a time.

    'MoveNext' is not a function in my code, so I am wondering if you might shed any light on what this might be related to so I can investigate further. Thanks.


    #2
    Hello pjsmith,

    Thanks for your post.

    When working with any issue, it is important to take steps to isolate the issue so that the exact line of code causing the behavior can be found.

    To determine what may be causing the issue you are reporting, you would need to identify which specific script and workspace are showing the issue.

    Please reduce the workspace chart by chart, and then script by script to determine which workspace and script is causing the issue.

    Then you could comment out specific lines of code in the script after that to see what line of code in the script is making the issue appear.

    Its helpful to think about when the error is occurring to target areas, and comment code from everywhere else quickly. If at any point after removing some code, the error stops, add the last removed item back.

    If the error is occurring while the script is loading, the issue is likely somewhere in OnStateChange(). In this situation its best to remove any logic in OnBarUpdate, remove any custom methods and classes, and remove as may properties as possible, while still being able to reproduce the error.

    If the error is occurring when saving a template, the issue is likely with a private or public variable declaration. First, remove all logic leaving the variable declarations behind. (Empty State.Configure, State.Dataloaded, State.Historical, OnBarUpdate, OnMarketData, and remove any custom methods.) Then start removing the variables one by one and testing until the error stops. When the error stops add the last removed item back. Ensure that this item is private or property serialized or using the Browsable(false) attribute. (More about the Browsable attribute below)

    If the error only occurs while the strategy is trading, this is likely a run time method. For this its best to use prints to understand the behavior.

    Let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      My bet is you have a thread context problem.

      Comment


        #4
        Couple of suggestions in addition to all those made by others above:
        • If you have not already done so, enable Debug Mode in the NinjaScript Editor so you can (hopefully) see the line number where the error is (supposedly) happening
        • MoveNext tends to be associated with enumeration; if you are doing that (explicitly or implicitly), take a look at the structures and ensure they're initialised as expected
        • Given that it is an "intermittent" issue, it sounds like there may be a timing issue or race condition involved, and you may wish to think along those lines too
        • Also, ensure all initialisation in OnStateChange is happening in the correct State for the action taken
        Thanks.
        Multi-Dimensional Managed Trading
        jeronymite
        NinjaTrader Ecosystem Vendor - Mizpah Software

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by selu72, Today, 02:01 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Zachary  
        Started by WHICKED, Today, 02:02 PM
        2 responses
        12 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Started by f.saeidi, Today, 12:14 PM
        8 responses
        21 views
        0 likes
        Last Post f.saeidi  
        Started by Mikey_, 03-23-2024, 05:59 PM
        3 responses
        51 views
        0 likes
        Last Post Sam2515
        by Sam2515
         
        Started by Russ Moreland, Today, 12:54 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Erick  
        Working...
        X