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 DanielSanMartin, Yesterday, 02:37 PM
            2 responses
            13 views
            0 likes
            Last Post DanielSanMartin  
            Started by DJ888, 04-16-2024, 06:09 PM
            4 responses
            12 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by terofs, Today, 04:18 PM
            0 responses
            11 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by nandhumca, Today, 03:41 PM
            0 responses
            8 views
            0 likes
            Last Post nandhumca  
            Started by The_Sec, Today, 03:37 PM
            0 responses
            6 views
            0 likes
            Last Post The_Sec
            by The_Sec
             
            Working...
            X