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

OnBarUpdate() Error

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

    OnBarUpdate() Error

    Hi,

    I have an NT 7 indicator that gives me the intermittent runtime error:

    3/21/2011 6:09:47 PM Default Error on plotting values to chart data box for indicator XXX'. Please check the 'OnBarUpdate' method: Object reference not set to an instance of an object.

    This occurs only when I am changing instruments or time; for example 5 min to 3 min chart.

    I have stripped my code down to almost nothing and I get the error even when I have empty OnBarUpdate(); i.e.

    protected override void OnBarUpdate()
    {
    }

    I have noticed and verified the if I reapply the indicator once the new instrument or time data are loaded, I no longer get the error.

    So it appears that this error results because the indicator is attempting to access data that is not yet present on the chart. Is there any way to force the indicator to wait until the new data series is loaded before executing? I am thinking of using something like

    if (CurrentBar > 0)

    in the OnBarUpdate() method.

    Any suggestions would be greatly appreciated. Thank you.

    #2
    Hello Zeos6,

    It depends really on the cause of the exception. You can use Try - Catch blocks to isolate the line of code and provide output on the exception. Help for these is available here:


    If the line of code is during OnBarUpdate() it shouldn't attempt to process unless one bar of data has elapsed. If you have a code snippet we can use that shows this, we're interested in reviewing for potential issues. Please let us know the steps as well.

    There is related issue discussed here, but this is the type of thing you would see at all times, and not resolved after reloading the script.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hi Ryan,

      I understand about the try...catch blocks and your other suggestions. As I mentioned, what makes this weird is that the error occurs even when there is no code inside the OnBarUpdate() method, and occurs during instrument change and/or time change. Should I be trying the catch blocks on the Initialize() content?

      Comment


        #4
        Yes, Try- Catch can be used generally in any area. It could be anything causing that type of message so if you can share the code snippet used we can take a look and give a run here.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Hi Ryan,

          Have to run at this time (didn't expect such a fast reply - thank you) but thank you. I will post the code tomorrow.

          Comment


            #6
            That message can also come from OnStartup(), or the Initialize(), not just the OnBarUpdate().

            Comment


              #7
              Hi Koganam,

              I did not think of that. Thank you for pointing this out. I will check this out and then will post.

              Comment


                #8
                One other point here: If you're running a multiseries script, the approach in your first post is a good idea, but for all series.

                if (CurrentBar < 0 || CurrentBars[1] < 0) return;
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Ryan,

                  This indeed is a multiseries script. Thank you for this excellent suggestion. I will certainly incorporate it once I hunt down the culprit for this error.

                  Comment


                    #10
                    Hi Ryan,

                    The situation has gotten even stranger. I have used try..catch block in my code and there were no exceptions. The code is basically sound as far as I can tell. I did discover something else, however. I have 7 charts in a workspace and I have linked them all, including the SuperDom. This error only occurs if the charts are linked with the last (red) link color. I actually relinked them with the first color (teal) and the error did not occur. Your input would be appreciated. Thank you.

                    Comment


                      #11
                      Thanks, Zeos. Can you attach the script used and we will give it a run here with those steps.
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Ryan,

                        Thank you. By the way, I checked all the linking colors and the error only occurs when using the last (red) linking color.
                        Attached Files

                        Comment


                          #13
                          Thank you for sharing the script. Unfortunately was not able to reproduce the issue. I switched instruments using all linking colors without issue. Can you check if you are able to reproduce with a simple, new workspace.

                          Please do the following:
                          Create a new workspace with File > Workspace > New Workspace
                          Create a new chart with File > New > Chart. Use without any other custom scripts applied.
                          Create a New SuperDom With File > New SuperDom

                          Link them together and try the instrument changes, If you are still seeing issues, isolate these factors:
                          • Static or Dynamic Superdom.
                          • What order did you click the link button(dom or chart first)?
                          • What was the instrument selected before the change?
                          • What chart interval is used?
                          • Which window did you use to change the instrument?
                          • How did you change the instrument? (Through default list, hotkeys, etc)
                          • What did you change the instrument to?
                          • Who is your data provider?
                          Ryan M.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi Ryan,

                            Well I am officially stumped. I have tested in a new workspace as you suggested and was not able to reproduce the issue. When I used my workspace, I was once again able to reproduce the issue. The issue occured both with a static as well as dynamic dom. I clicked on the dom to change from TF to 6E then to CL.The issue occurs regardless of whether the change is initiated from the dom or a chart. The issue also occurs regardless of the sequence of the change; i.e. it also occured going from 6E to CL to TF. The initial instrument was TF. One chart was 1440min, 1 chart was 100V, one was 500V, one was 2500V, one chart was 45S, one chart was 12S, and one chart was 30min. By the way, once again the error did not occur when a different linking color was used.

                            P.S. The vol charts were candles, the other charts were OHLC bars. Data provider is Rithmic.
                            Last edited by Zeos6; 03-23-2011, 03:53 PM.

                            Comment


                              #15
                              OK - thanks for checking into that. We can check this on our end with your workspace. You can use Help > Mail to support feature. In the subject write Attn RyanM 455319 in subject.

                              Make sure workspaces is checked as well as log / trace. Let us know the name of the workspace that experiences the issue as well.
                              Ryan M.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by geddyisodin, 04-25-2024, 05:20 AM
                              8 responses
                              61 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by jxs_xrj, 01-12-2020, 09:49 AM
                              4 responses
                              3,287 views
                              1 like
                              Last Post jgualdronc  
                              Started by Option Whisperer, Today, 09:55 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post Option Whisperer  
                              Started by halgo_boulder, 04-20-2024, 08:44 AM
                              2 responses
                              22 views
                              0 likes
                              Last Post halgo_boulder  
                              Started by mishhh, 05-25-2010, 08:54 AM
                              19 responses
                              6,189 views
                              0 likes
                              Last Post rene69851  
                              Working...
                              X