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

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 George21, Today, 10:07 AM
          0 responses
          0 views
          0 likes
          Last Post George21  
          Started by Stanfillirenfro, Today, 07:23 AM
          8 responses
          23 views
          0 likes
          Last Post Stanfillirenfro  
          Started by DayTradingDEMON, Today, 09:28 AM
          2 responses
          15 views
          0 likes
          Last Post DayTradingDEMON  
          Started by navyguy06, Today, 09:28 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by cmtjoancolmenero, Yesterday, 03:58 PM
          8 responses
          32 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X