NexusFi: Find Your Edge


Home Menu

 





Error: Object reference not set to an instance of an object.


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one gomad with 5 posts (0 thanks)
    2. looks_two Zondor with 2 posts (5 thanks)
    3. looks_3 stearno with 2 posts (0 thanks)
    4. looks_4 devdas with 1 posts (1 thanks)
    1. trending_up 12,031 views
    2. thumb_up 10 thanks given
    3. group 3 followers
    1. forum 11 posts
    2. attach_file 4 attachments




 
Search this Thread

Error: Object reference not set to an instance of an object.

  #1 (permalink)
 gomad 
Tirgu Mures, Romania
 
Experience: Intermediate
Platform: Ninja
Broker: ZenFire
Trading: CL, GC
Posts: 36 since Sep 2010
Thanks Given: 42
Thanks Received: 7

I have read all threads that I found about this problem, but I didn't find any solution for my particular situation.

I'm trying to find some significant statistical correlations on market (using GraphPad) and for this I use many custom indicators (to get data out of the market).

Here is an indicator which I've coded this days, but when I use it on Market Replay or Sim I get the following error (in Log tab):


Quoting 
Error on calling 'OnBarUpdate' method for indicator 'aTrendEnter' on bar 56 (this error is repetitive, not just on this bar): Object reference not set to an instance of an object.

Using try-catch I have the following text in my Output Window:


Quoting 
3/23/2011 8:36:54 AM System.NullReferenceException: Object reference not set to an instance of an object.
at NinjaTrader.Data.MemBars.GetOpen(Int32 index)
at NinjaTrader.Data.Bars.GetOpen(Int32 index)
at NinjaTrader.Indicator.DataSeriesHelper.get_Item(In t32 barsAgo)
at NinjaTrader.Indicator.aTrend2.OnBarUpdate()

The lines isolated in "try" are as follows:

 
Code
for (int i = 0;  i < Period; i++)
				
				
				
        	{
				try {
					if (Close[i] > Open[i-2] && High[i-2] < Close[i-8])
						var2 = var2 + 1;
				}
				
				catch (Exception e)
						
			
			{
				/* With our caught exception we are able to generate log entries that go to the Control Center logs and also print more detailed information
				about the error to the Output Window. */
				
				// Submits an entry into the Control Center logs to inform the user of an error
				Log("SampleTryCatch Error: Please check your indicator for errors.", LogLevel.Error);
				
				// Prints the caught exception in the Output Window
				Print(Time[0] + " " + e.ToString());
			}
								
			}
			
			Short.Set(var2);
When Market Replay is playing or market is moving on sim, my chart is going crazy. Look at this 8 Range Chart on CL:





And here is the indicator attached:

aTrend2.zip

Can someone help me with this problem?

Thank you.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Exit Strategy
NinjaTrader
Futures True Range Report
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
Battlestations: Show us your trading desks!
26 thanks
The Program
18 thanks
  #3 (permalink)
 
Zondor's Avatar
 Zondor 
Portland Oregon, United States
 
Experience: Beginner
Platform: NinjatraderŽ
Broker: CQG, Kinetick
Trading: Gameplay KlownbineŽ Trading of Globex
Posts: 1,333 since Jul 2009
Thanks Given: 1,246
Thanks Received: 2,731


It is good that you are using try{ }catch blocks for debugging.

In the OnStartUp method try doing a one time assignment of arbitrary values to the Open, Close and High data series to force them to be created.

In the OnBarUpdate method try testing for null values of the data series before attempting to access or manipulate them:

 
Code
If (Close==null || Open==null || High ==null) return:

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 gomad 
Tirgu Mures, Romania
 
Experience: Intermediate
Platform: Ninja
Broker: ZenFire
Trading: CL, GC
Posts: 36 since Sep 2010
Thanks Given: 42
Thanks Received: 7


Zondor View Post

In the OnStartUp method try doing a one time assignment of arbitrary values to the Open, Close and High data series to force them to be created.

Zondor,

Thank you for your reply.

Can you help me with an example of "one time assignment of arbitrary values to the Open, Close and High data series to force them to be created"?

Started this thread Reply With Quote
  #5 (permalink)
 gomad 
Tirgu Mures, Romania
 
Experience: Intermediate
Platform: Ninja
Broker: ZenFire
Trading: CL, GC
Posts: 36 since Sep 2010
Thanks Given: 42
Thanks Received: 7


gomad View Post
Zondor,

Thank you for your reply.

Can you help me with an example of "one time assignment of arbitrary values to the Open, Close and High data series to force them to be created"?

Becouse it is true that the indicator is deactivated when I use the code you suggested above:


Quoting 
if (Close==null || Open==null || High ==null) return;


Started this thread Reply With Quote
  #6 (permalink)
 
devdas's Avatar
 devdas 
Al,India
 
Experience: Advanced
Platform: NinjaTrader
Broker: Z
Trading: NiftyFuture
Posts: 1,562 since Feb 2010
Thanks Given: 1,513
Thanks Received: 1,701


gomad View Post

Error on calling 'OnBarUpdate' method for indicator 'aTrendEnter' on bar 56 (this error is repetitive, not just on this bar): Object reference not set to an instance of an object.

from this i guess its a logical error in indicator construction than usual Initialization or OnStartUp error.
This type had happened with me in past , throwing error on different bars..some time indic working and some time shewed error. In end , in my case it turned out logical error in indicator.

Harvest The Moon
Nest The Market
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #7 (permalink)
 gomad 
Tirgu Mures, Romania
 
Experience: Intermediate
Platform: Ninja
Broker: ZenFire
Trading: CL, GC
Posts: 36 since Sep 2010
Thanks Given: 42
Thanks Received: 7


devdas View Post
from this i guess its a logical error in indicator construction than usual Initialization or OnStartUp error.
This type had happened with me in past , throwing error on different bars..some time indic working and some time shewed error. In end , in my case it turned out logical error in indicator.

Yes, but the only condition the indicator have is this:

 
Code
for (int i = 0;  i < Period; i++)
				
				
				
        	{
				try {
					if (Close[i] > Open[i-2] && High[i-2] < Close[i-8])
						var2 = var2 + 1;
				}
				
				catch (Exception e)
						
			
			{
				/* With our caught exception we are able to generate log entries that go to the Control Center logs and also print more detailed information
				about the error to the Output Window. */
				
				// Submits an entry into the Control Center logs to inform the user of an error
				Log("SampleTryCatch Error: Please check your indicator for errors.", LogLevel.Error);
				
				// Prints the caught exception in the Output Window
				Print(Time[0] + " " + e.ToString());
			}
								
			}
			
			Short.Set(var2);
I don't see where the error can be in this condition:

 
Code
if (Close[i] > Open[i-2] && High[i-2] < Close[i-8])

Started this thread Reply With Quote
  #8 (permalink)
 
Zondor's Avatar
 Zondor 
Portland Oregon, United States
 
Experience: Beginner
Platform: NinjatraderŽ
Broker: CQG, Kinetick
Trading: Gameplay KlownbineŽ Trading of Globex
Posts: 1,333 since Jul 2009
Thanks Given: 1,246
Thanks Received: 2,731


Quoting 
Can you help me with an example of "one time assignment of arbitrary values to the Open, Close and High data series to force them to be created"?

in OnStartUp maybe this will help:

 
Code
double dummy;
dummy=Close[0];
dummy=Open[0];
dummy=High{0];
How are your dataeries declared? Are they public or private?

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #9 (permalink)
 gomad 
Tirgu Mures, Romania
 
Experience: Intermediate
Platform: Ninja
Broker: ZenFire
Trading: CL, GC
Posts: 36 since Sep 2010
Thanks Given: 42
Thanks Received: 7


Zondor View Post
in OnStartUp maybe this will help:

 
Code
double dummy;
dummy=Close[0];
dummy=Open[0];
dummy=High{0];

Unfortunately it is not working. The same error.


Quoting 
How are your dataeries declared? Are they public or private?

Where I find this information?

Is there some "default" for this?

All my code is written in "protected override void On bar update" and "protected override void Initialize".

Started this thread Reply With Quote
  #10 (permalink)
 
Jigsaw Trading's Avatar
 Jigsaw Trading  Jigsaw Trading is an official Site Sponsor
 
Posts: 2,988 since Nov 2010
Thanks Given: 831
Thanks Received: 10,393


Uggghhh - this error... seriously - in the year 2011, is this the best we can get.

I have 2 bug bears with this type of error. First - it gets reported as an error in "OnBarUpdate" event but it could actually be in any method called from within OnBarUpdate - which in most cases can be pretty much anywhere.

The other thing is it's a generic message - .NET must know the object in question but doesn't tell us what it is...

ugghhh...

Anyway - I think you are looking for past values on the high, open & close, right:

if (Close[i] > Open[i-2] && High[i-2] < Close[i-8])

Shouldn't this be:

if (Close[i] > Open[i+2] && High[i+2] < Close[i+8]) ????

If i = 0, then your Close[i-8] is going to be resolve to Close[-8] - is that looking for 8 bars in the future ???? To look 8 bars back, you would do Close[8]. So - if you look further back, you need to add to i.

Hope this helps

Pete

Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on December 22, 2014


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts