![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Apr 2007
Location: , ,
Posts: 26
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Apr 2007
Location: , ,
Posts: 26
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
- 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.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Apr 2007
Location: , ,
Posts: 26
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#6 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
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
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Apr 2007
Location: , ,
Posts: 26
Thanks: 0
Thanked 0 times in 0 posts
|
Sent by mail.
|
|
|
|
|
|
#8 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
This is a bug which will be fixed with next update. Thanks for reporting that one.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
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
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Junior Member
Join Date: Apr 2007
Location: , ,
Posts: 26
Thanks: 0
Thanked 0 times in 0 posts
|
I'm impressed with the fast turn-around on this.
I will test the custom version first thing AM. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|