Go Back   NinjaTrader Support Forum > NinjaTrader 7 > 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: 264
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: 10,083
Thanks: 2
Thanked 31 times in 24 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: 264
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: 10,083
Thanks: 2
Thanked 31 times in 24 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 Development 4 01-24-2008 03:20 PM
OnBarUpdate "context" in user defined method kgillis23 General Development 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 Platform Technical Support 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 02:14 AM.

Futures, foreign currency and options 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.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content. Visit the CFTC resources for education regarding the industry and signs of fraud.