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 on calling 'OnBarUpdate' method for indicator ' ' on bar 0:

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

    Error on calling 'OnBarUpdate' method for indicator ' ' on bar 0:

    Key cannot be null.


    What does this mean?

    #2
    kaywai,

    If possible, could you post your OnBarUpdate() code? This will help immensely in solving your issue.

    I look forward to assisting you.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Adam,

      Please see attached.

      Regards

      Kay Wai
      Last edited by kaywai; 10-31-2011, 06:31 PM.

      Comment


        #4
        kaywai,

        The issue is here :
        Code:
        		private string BSTDSTLineTag1 = null;
        		private string BSTDSTLineTag2 = null;
        Because you are assigning a null tag to your draw objects (in this case the lines). You need to have a tag set up for them so you can reference them later.

        Those variables affect this section.
        Code:
        			
        			if (!canceldrawtdstbuyline1)
        			{
        				DrawLine(BSTDSTLineTag1, true, BSTDST1bar, BSTDST1, 0, BSTDST1, Color.Green, DashStyle.Dash, 1);
        				
        			}
        			if (!canceldrawtdstbuyline2)
        			{
        				if (BSTDST2 > BSTDST1)
        				{
        					DrawLine(BSTDSTLineTag2, true, BSTDST2bar, BSTDST2 ,0, BSTDST2, Color.Green, DashStyle.Dash, 1);
        				}
        			}
        Please let me know if I may assist further.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Hi Adam,

          Not sure I follow you.

          If you look at the code below, I have set up tags so that I can reference them, or haven't I? Please see the code in bold. If I have it all misunderstood, would you mind explaining it in layman terms.

          Why do I have the tags this way? It worked well when I was drawing a rectangle in a similar manner. Hope you can assist me further.

          Code:
          [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
          if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] ((TDBuyExtendedSetupFX().buysetupmoveiscompleted) && (BSTDST1 == [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]))[/COLOR]
          {
          BSTDST1 = TDBuyExtendedSetupFX().hhbs;
          BSTDST1bar = TDBuyExtendedSetupFX().hhbsbar;
          Print(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]);
          Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BSTDST1 = "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + BSTDST1.ToString());
          Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BSTDST1bar = "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + BSTDST1bar.ToString());
          BSTDSTLine1 = CurrentBar;
          [B]BSTDSTLineTag1 = [/B][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][B]"BSTDST1"[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][B]+CurrentBar;[/B]
          }
          [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ((TDBuyExtendedSetupFX().buysetupmoveiscompleted) && (BSTDST1 != [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]))
          {
          BSTDST2 = BSTDST1;
          BSTDST2bar = BSTDST1bar;
          BSTDST1 = TDBuyExtendedSetupFX().hhbs;
          BSTDST1bar = TDBuyExtendedSetupFX().hhbsbar;
          Print(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]);
          Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BSTDST1 = "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + BSTDST1.ToString());
          Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BSTDST1bar = "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + BSTDST1bar.ToString());
          Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BSTDST2 = "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + BSTDST2.ToString());
          Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"BSTDST2bar = "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + BSTDST2bar.ToString());
          BSTDSTLine1 = CurrentBar;
          [B]BSTDSTLineTag1 = [/B][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][B]"BSTDST1"[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][B]+CurrentBar;[/B]
          BSTDSTLine2 = CurrentBar;
          [B]BSTDSTLineTag2 = [/B][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][B]"BSTDST2"[/B][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][B]+CurrentBar;[/B]
          [B]}[/B]
          [/SIZE][/FONT][/SIZE][/FONT]

          Comment


            #6
            kaywai,

            It is possible what is occurring is that initially the tags are not set because the two conditions in your if and else-if statements aren't true for the first bar until something else is set. So it skips over them and attempts to draw a line with a null tag. I would double check your if/else, and if statement logic and see if you need to perhaps move your logic around, or set up some flag that skips over the drawing part on the first bar. E.g.

            bool firstRunFlag = true;

            if ( firstRunFlag == true )
            {
            firstRunFlag = false;
            return;
            }

            //all your other code here

            Make liberal use of Print() statements and double check all your variables are getting assigned what you think they should be assigned. Also, you can use Try/Catch blocks to catch errors and handle them more gracefully. For a helpful reference sample please see the link below.



            Please let me know if I may assist further.
            Adam P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by PaulMohn, Today, 03:49 AM
            0 responses
            3 views
            0 likes
            Last Post PaulMohn  
            Started by inanazsocial, Today, 01:15 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by rocketman7, Today, 02:12 AM
            0 responses
            10 views
            0 likes
            Last Post rocketman7  
            Started by dustydbayer, Today, 01:59 AM
            0 responses
            2 views
            0 likes
            Last Post dustydbayer  
            Started by trilliantrader, 04-18-2024, 08:16 AM
            5 responses
            23 views
            0 likes
            Last Post trilliantrader  
            Working...
            X