NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 04-30-2007, 01:05 AM   #1
MindSabre
Junior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 26
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

I'm getting the following error when Analyzing a strategy:

Strategy,Error on calling 'OnBarUpdate' method for strategy 'XYZ': Object reference not set to an instance of an object.

How to debug? How can I find out which line of code in OnBarUpdate is generating the error?


MindSabre is offline  
Reply With Quote
Old 04-30-2007, 01:26 AM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Post imported post

You will have to add debug print statements to each area of your codethat has a variable that holds an object. Somewhere your code is accessing an object variable that does not hold an object.


For example:

if (myObject == null)
Print("myObjectis null);

Ray
NinjaTrader_Ray is offline  
Reply With Quote
Old 04-30-2007, 10:12 PM   #3
MindSabre
Junior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 26
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

The error is being caused by the following line of code:

if (Position.GetProfitLoss(Close[0],PerformanceUnit.Points)>=0)



When I run the code without this conditional statement the error doesn't occur.

What am I doing wrong? Do I need to initialize the Position object?



Is there any way to debug NS using VS or another debugger?
MindSabre is offline  
Reply With Quote
Old 05-01-2007, 01:14 AM   #4
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Post imported post

- do you have code line below in the OnBarUpdate method? I just tried on a blank strategy and could not experience any issue
- there is no need to initialize the Position object
- you can not debug your NS strategy by a debugger. I suggest putting in Print() statements.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 05-01-2007, 02:38 AM   #5
MindSabre
Junior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 26
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Yes, it is in the OnBarUpdate method as part of more code. When I just remove this line and let the rest of the code run, it runs fine. When I add this line as a condition to part of the code (along and shortexit), the object error appears.




MindSabre is offline  
Reply With Quote
Old 05-01-2007, 02:45 AM   #6
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Post imported post

Can you please PM me your strategy to "dierk AT ninjatrader DOT com" in order reproduce?

I also would need:
- which instrument is this
- which timeframe (1 minute? else?)
- please send me a screenshot of your strategy settings as well

Thanks
NinjaTrader_Dierk is offline  
Reply With Quote
Old 05-01-2007, 03:16 AM   #7
MindSabre
Junior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 26
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

Sent by mail.
MindSabre is offline  
Reply With Quote
Old 05-01-2007, 04:06 AM   #8
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Post imported post

This is a bug which will be fixed with next update. Thanks for reporting that one.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 05-01-2007, 05:52 AM   #9
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Post imported post

We created a custom build holding this fix. Please:
- uninstall NT6 via control panel
- clear your browser cache
- install custom build from here: http://www.ninjatrader-support.com/n...er.Install.msi
NinjaTrader_Dierk is offline  
Reply With Quote
Old 05-01-2007, 07:36 AM   #10
MindSabre
Junior Member
 
Join Date: Apr 2007
Location: , ,
Posts: 26
Thanks: 0
Thanked 0 times in 0 posts
Post imported post

I'm impressed with the fast turn-around on this.

I will test the custom version first thing AM.


MindSabre is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 05:08 AM.