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 Christopher_R, Today, 12:29 AM
        0 responses
        9 views
        0 likes
        Last Post Christopher_R  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        166 responses
        2,235 views
        0 likes
        Last Post sidlercom80  
        Started by thread, Yesterday, 11:58 PM
        0 responses
        3 views
        0 likes
        Last Post thread
        by thread
         
        Started by jclose, Yesterday, 09:37 PM
        0 responses
        8 views
        0 likes
        Last Post jclose
        by jclose
         
        Started by WeyldFalcon, 08-07-2020, 06:13 AM
        10 responses
        1,415 views
        0 likes
        Last Post Traderontheroad  
        Working...
        X