Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Failed to call method "Initialize" for indicator 'Test': Object reference not set to

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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

    #2
    - you can't access neither Instrument nor Bars in Initialize()
    - try BarsPeriod instead

    Comment


      #3
      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?

      Originally posted by NinjaTrader_Dierk View Post
      - you can't access neither Instrument nor Bars in Initialize()
      - try BarsPeriod instead

      Comment


        #4
        These are the limitations plus you only can call Add in Initialize()

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by WeyldFalcon, 08-07-2020, 06:13 AM
        11 responses
        1,421 views
        0 likes
        Last Post jculp
        by jculp
         
        Started by RubenCazorla, Today, 09:07 AM
        0 responses
        1 view
        0 likes
        Last Post RubenCazorla  
        Started by BarzTrading, Today, 07:25 AM
        2 responses
        29 views
        1 like
        Last Post BarzTrading  
        Started by devatechnologies, 04-14-2024, 02:58 PM
        3 responses
        21 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by tkaboris, Today, 08:01 AM
        0 responses
        6 views
        0 likes
        Last Post tkaboris  
        Working...
        X