Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Object Reference error on applying strategy

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

    Object Reference error on applying strategy

    Hi,

    I have no problem when compiling my code, i have tested it in visual studio c#, and its working fine.
    I am getting an error while applying the strategy to my chart.

    *NT** Enabling NinjaScript strategy
    **NT** Error on calling 'OnBarUpdate' method for strategy 'GetBuySellPrint/2a3c76e798bc43919bbe5b4f281d2018': Object reference not set to an instance of an object.

    and then no output at all.

    Any idea why i am getting this (flummoxed because the compiler is not returning an error)
    Code:
    if(IsTimeTrue()==false)
    				return;
    			if(BarsInProgress == 1)
    			{
    				lock(lastprint)
    				{
    									
    				int nodecount= 0 ;
    				LinkedListNode<Prints> listnode = printslist.First;
    				Prints lastprintinlist = new Prints();
    					
    				nodecount = printslist.Count;
    				lastprintinlist = printslist.Last.Value;
    												
    				if(nodecount==0)
    					return;
    				if (lastprint.CompareTo(lastprintinlist)==true)
    					return;
    									
    				listnode = printslist.Find(lastprint);
    				
    				if (listnode == null)
    				{
    					listnode = printslist.First;
    				}
    				else
    				{
    					listnode = listnode.Next;
    				}
    				
    				while(listnode!= null)
    				{
    					Print("from List");				// Process fresh prints
    					listnode.Value.PrintToScreen();
    					listnode = listnode.Next;
    				}				
    				lastprint = printslist.Last.Value;
    			}	}				
    		
            }
    Here is the code in OnBarUpdate()

    #2
    Hi nemesis45,

    The code here does not show how variables and functions are being created, what scope they have, and where in file they are placed.

    lock(), and the Prints() class or collection are both declared outside of this code.

    I recommend that you add prints to your code every few lines of code so that you can see on which line the script stops. This will identify the variable that is being used as an object though it is not set to an object.

    Do this with the Print(); call and your output will go to the Output window. (Tools -> Output Window).

    It would be good to see if any of the variables are equal to null.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      EDIT: Thanks i found the error.

      LinkedList.Count is returning null instead of 0 , when the list is empty.
      fixed it thanks a lot
      Last edited by nemesis45; 04-10-2014, 11:34 AM.

      Comment


        #4
        Hi nemesis45,

        If there is a print as the first line of your script before anything else, this print on the first bar should come out.

        If not, then it would appear that OnBarUpdate isn't even running which would mean you would not get that message.

        At this point I could test this script for you if you would like. I would ask that you reduce the code down to only the code necessary to reproduce this issue.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Yes i had not handled null exception. did that its working now.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          633 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          364 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          567 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          568 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X