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

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 04-23-2008, 12:27 PM   #1
clearpicks
Senior Member
 
Join Date: Jan 2008
Posts: 257
Thanks: 0
Thanked 0 times in 0 posts
Default Failed to call method "Initialize" for indicator 'Test': Object reference not set to

In my indicator script, in Initialize(), I need to access information of the time frame and intrument name so that the indicator can be customized according to the timeframe and instrument information. For example, if the indicator is running on a daily chart, two plots need to be added to display bollinger while on intraday chart ADD(Plot) should not be called in initialization. So in Initialize(), I use
isOnDailyChart = Bars.Period.Id == PeriodType.Day && Bars.Period.Value == 1;
symbol = Instrument.MasterInstrument.Name;
to access timeframe and symbol information. However each time in NT Log window I get an error message:

Failed to call method "Initialize" for indicator 'Test': Object reference not set to an instance of an object.

Although this error message seems not affecting the correct running of my indicator, there may be a lot such error message when I swtich timeframe and symbol frequently, which is quite annoying.

My question is whether I should access the member variables of Bars and Instrument? Why does my indicator work fine with such error message?
What is the correct way to access time frame and instrument information within Initialize() function?
Attached Files
File Type: cs Test.cs (5.4 KB, 4 views)
clearpicks is offline  
Reply With Quote
Old 04-23-2008, 12:35 PM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 7 times in 7 posts
Default

- you can't access neither Instrument nor Bars in Initialize()
- try BarsPeriod instead
NinjaTrader_Dierk is offline  
Reply With Quote
Old 04-23-2008, 12:43 PM   #3
clearpicks
Senior Member
 
Join Date: Jan 2008
Posts: 257
Thanks: 0
Thanked 0 times in 0 posts
Default

BarsPeriod only works for StrategyBase not IndicatorBase.

Is there any method to create different number of plots or lines using ADD(Plot) and ADD(Line) based on the timeframe and the primary instrument information? If I move those initialization code in Initialize() to OnBarUpdate() with flag defined to make sure the initialization part only executed once, shall I encounter any error? Is my work around solution correct?

Quote:
Originally Posted by NinjaTrader_Dierk View Post
- you can't access neither Instrument nor Bars in Initialize()
- try BarsPeriod instead
clearpicks is offline  
Reply With Quote
Old 04-23-2008, 12:53 PM   #4
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 7 times in 7 posts
Default

These are the limitations plus you only can call Add in Initialize()
NinjaTrader_Dierk 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error on calling the 'OnOrderUpdate' method for strategy 'maslope': Object reference scriabinop23 General Programming 4 01-24-2008 03:20 PM
OnBarUpdate "context" in user defined method kgillis23 General Programming 3 01-08-2008 09:40 PM
Multiple Calls to "Initialize()" Method on Strategy Start tomcat Strategy Development 3 11-04-2007 02:12 PM
Line "names" in Indicator Box change to "Line" after modification higler Charting 3 05-02-2007 06:05 AM
Control center "strategies" tab, "Positions tab, and "Market Analyzer" not funk101 Strategy Development 6 04-10-2007 03:44 AM


All times are GMT -6. The time now is 08:07 PM.

FULL RISK DISCLOSURE: Futures trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.