Error: Object reference not set to an instance of an object. - NinjaTrader Programming | futures io social day trading
futures io futures trading


Error: Object reference not set to an instance of an object.
Updated: Views / Replies:4,434 / 11
Created: by gomad Attachments:4

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors – all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you don’t need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 4  
 
Thread Tools Search this Thread
 

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

  #1 (permalink)
Elite Member
Tirgu Mures, Romania
 
Futures Experience: Intermediate
Platform: Ninja
Broker/Data: ZenFire
Favorite Futures: CL, GC
 
Posts: 36 since Sep 2010
Thanks: 42 given, 6 received

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

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:

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


And here is the indicator attached:

aTrend2.zip

Can someone help me with this problem?

Thank you.

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,327 since Jul 2009
Thanks: 1,246 given, 2,635 received

Object Ref not set to Instance of an Object


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:

Reply With Quote
The following 3 users say Thank You to Zondor for this post:
 
  #4 (permalink)
Elite Member
Tirgu Mures, Romania
 
Futures Experience: Intermediate
Platform: Ninja
Broker/Data: ZenFire
Favorite Futures: CL, GC
 
Posts: 36 since Sep 2010
Thanks: 42 given, 6 received


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"?

Reply With Quote
 
  #5 (permalink)
Elite Member
Tirgu Mures, Romania
 
Futures Experience: Intermediate
Platform: Ninja
Broker/Data: ZenFire
Favorite Futures: CL, GC
 
Posts: 36 since Sep 2010
Thanks: 42 given, 6 received


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;


Reply With Quote
 
  #6 (permalink)
 Vendor: www.edevaay.com 
Al,India
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: RKG
Favorite Futures: NiftyFuture
 
devdas's Avatar
 
Posts: 1,547 since Feb 2010
Thanks: 1,460 given, 1,661 received


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
Reply With Quote
The following user says Thank You to devdas for this post:
 
  #7 (permalink)
Elite Member
Tirgu Mures, Romania
 
Futures Experience: Intermediate
Platform: Ninja
Broker/Data: ZenFire
Favorite Futures: CL, GC
 
Posts: 36 since Sep 2010
Thanks: 42 given, 6 received


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])

Reply With Quote
 
  #8 (permalink)
Elite Member
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,327 since Jul 2009
Thanks: 1,246 given, 2,635 received


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?

Reply With Quote
The following 2 users say Thank You to Zondor for this post:
 
  #9 (permalink)
Elite Member
Tirgu Mures, Romania
 
Futures Experience: Intermediate
Platform: Ninja
Broker/Data: ZenFire
Favorite Futures: CL, GC
 
Posts: 36 since Sep 2010
Thanks: 42 given, 6 received


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".

Reply With Quote
 
  #10 (permalink)
Market Wizard
Bangkok
 
Futures Experience: Intermediate
Platform: MultiCharts.NET, S5, Ninj
Broker/Data: AMP, S5, IB
Favorite Futures: ES
 
DionysusToast's Avatar
 
Posts: 2,671 since Nov 2010
Thanks: 777 given, 8,738 received
Forum Reputation: Legendary


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

Reply With Quote
The following 4 users say Thank You to DionysusToast for this post:

Reply



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

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
object name ? sam028 NinjaTrader Programming 3 March 14th, 2011 10:55 AM
ninja trader object reference not set to an instance kk240 NinjaTrader Programming 4 December 29th, 2010 11:16 AM
need help :: cant fix :: Object reference not set to an instance of an object Trader.Jon NinjaTrader Programming 9 November 3rd, 2010 11:55 AM
Object reference not set to an instance... dsraider NinjaTrader Programming 5 July 30th, 2010 09:17 AM
EasyLanguage Object Reference philloo TradeStation 2 June 18th, 2010 03:56 AM


All times are GMT -4. The time now is 10:49 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-14 in 0.14 seconds with 20 queries on phoenix via your IP 54.90.207.75