PDA

View Full Version : Strategy Error


MindSabre
04-30-2007, 01:05 AM
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?

NinjaTrader_Ray
04-30-2007, 01:26 AM
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

MindSabre
04-30-2007, 10:12 PM
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?

NinjaTrader_Dierk
05-01-2007, 01:14 AM
- 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.

MindSabre
05-01-2007, 02:38 AM
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.

NinjaTrader_Dierk
05-01-2007, 02:45 AM
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

MindSabre
05-01-2007, 03:16 AM
Sent by mail.

NinjaTrader_Dierk
05-01-2007, 04:06 AM
This is a bug which will be fixed with next update. Thanks for reporting that one.

NinjaTrader_Dierk
05-01-2007, 05:52 AM
We created a custom build holding this fix. Please:
- uninstall NT6 via control panel
- clear your browser cache
- install custom build from here: www.ninjatrader-support.com/ninjatrader/nt6.custom/NinjaTrader.Install.msi

MindSabre
05-01-2007, 07:36 AM
I'm impressed with the fast turn-around on this.

I will test the custom version first thing AM.