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 'OnBarUpdate' method Object ref not set to an instance of an obj."

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

    "Error calling 'OnBarUpdate' method Object ref not set to an instance of an obj."

    5/20/2022 4:05:56 PM Default Strategy 'NewRegSlope': Error on calling 'OnBarUpdate' method on bar 5074: Object reference not set to an instance of an object.
    Does anyone know why I keep getting this? Very frustrating as a newbie. I've been using the strategy Wizard to create the basic layout of the programs, so I would have expected not to have received this error (e.g. nothing in here that wasn't a function or object cranked out by the wizard). Any help or suggestion would be appreciated.

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 2)
    return;
    goLong = false;
    goShort = false;

    goLong = ( (LinRegSlope1[0]
    Last edited by wwhalenc; 05-23-2022, 10:26 AM.

    #2
    Hello wwhalenc,

    Thank you for your note.

    I'm not seeing anything too obvious in your code sample here that would obviously throw that error. However, I'd like to test on my end if I may. Please export the strategy from Tools > Export > NinjaScript Addon. Do not check the box to export as a compiled assembly or I will not be able to review your logic. Please attach the resulting .Zip file to your reply.

    Additionally, if you could specify the instrument, bar type, and interval for the chart this occurred on?

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thanks, Kate. This is for the nasdaq micro 6-22 on the one minute chart (bar type is whatever the default would be). Thanks for your help. -C
      Last edited by wwhalenc; 05-23-2022, 12:32 PM.

      Comment


        #4
        So what is actually calling OnBarUpdate (e.g. just wondering if there's a way to test that the relevant object is instantiated before this is called)?
        Last edited by wwhalenc; 05-23-2022, 10:38 AM.

        Comment


          #5
          Hello wwhalenc,

          Thank you for your replies.

          I'm not getting the same error on MNQ 06-22 1 minute chart using the default settings. If you apply it to a chart currently do you get the same error on the historical data?

          Thanks in advance; I look forward to assisting you further.
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Hi Kate, I'm new and somewhat clueless. When I use "Strategy Performance" it creates the stats without issue, so I presume it runs fine with historical data?

            Comment


              #7
              Hello wwhalenc,

              Thank you for your reply.

              I'm trying to replicate but it's taking a huge number of trades and bogging down playback with the default settings. Can you confirm the settings you were using when running the strategy? If you can provide a screenshot of the Strategies window showing the settings that would be very helpful.

              Thanks in advance; I look forward to assisting you further.
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Hi Kate,
                The strategy immediately dies for me, so you're getting further than me.

                Attached Files

                Comment


                  #9
                  Hello wwhalenc,

                  Thank you for your reply.

                  I note we seem to be running different versions of the strategy as the one you previously provided me with has two inputs for Trailing Value while yours only shows one. Can you provide the version you're currently using so we can be certain we're testing the same thing?

                  Thanks in advance; I look forward to assisting you further.
                  Kate W.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Kate, Since your copy at least works a little, I went and deleted the strategy and re-imported the exact same one I sent. We should be looking at exactly the same strategy. Both entries for Trailing value should be 15 or higher.

                    Comment


                      #11
                      Hello wwhalenc,

                      Thank you for your reply.

                      I've tested this using Market Replay data in the playback connection over MNQ 06-22 1 minute data and was not able to replicate the error. Have you been able to replicate the error at all using the same version I'm testing, either on live data using the Sim101 account or on Market Replay with the Playback account?

                      Thanks in advance; I look forward to assisting you further.
                      Kate W.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Kate, I went in and put a ton of Print statements in there ... this happens on Live data or the Sim account. I found out that it's dying where it's first trying to reference the entryOrder object. Is there a way to pause until after the order is filled? -Chris


                        [code]

                        if (Position.MarketPosition == MarketPosition.Flat)
                        {
                        if ( goLong || goShort) {
                        if ( goLong ){
                        entryOrder = EnterLong(Convert.ToInt32(DefaultQuantity), @"LE") ;
                        }

                        if ( goShort){
                        entryOrder = EnterShort(Convert.ToInt32(DefaultQuantity), @"SE") ;
                        }
                        entryPrice = entryOrder.AverageFillPrice; /* <<<<------------ */
                        waterMark = Close[0] ;


                        if (entryPrice > 0 ) {
                        Log("!!!!!!!!!!!! Entry price is " + entryOrder.AverageFillPrice, LogLevel.Information);

                        Comment


                          #13
                          Hello wwhalenc,

                          Thank you for your reply.

                          That's very helpful. You're hitting an error because when you're trying to check entryOrder.AverageFillPrice that the entryOrder hasn't yet been created and returns null, causing an error. It's more reliable to assign the order to the order variable in OnOrderUpdate so you can be certain the order's been created. You can take a look at this example from our help guide that illustrates this approach:



                          Please let us know if we may be of further assistance to you.

                          Kate W.NinjaTrader Customer Service

                          Comment


                            #14
                            Breakthrough! Thanks for help and patience, Kate.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Kaledus, Today, 01:29 PM
                            1 response
                            6 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Started by frankthearm, Yesterday, 09:08 AM
                            13 responses
                            45 views
                            0 likes
                            Last Post frankthearm  
                            Started by PaulMohn, Today, 12:36 PM
                            2 responses
                            16 views
                            0 likes
                            Last Post PaulMohn  
                            Started by Conceptzx, 10-11-2022, 06:38 AM
                            2 responses
                            55 views
                            0 likes
                            Last Post PhillT
                            by PhillT
                             
                            Started by yertle, Yesterday, 08:38 AM
                            8 responses
                            37 views
                            0 likes
                            Last Post ryjoga
                            by ryjoga
                             
                            Working...
                            X