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 gemify, 11-11-2022, 11:52 AM
        6 responses
        803 views
        2 likes
        Last Post ultls
        by ultls
         
        Started by ScottWalsh, Today, 04:52 PM
        0 responses
        3 views
        0 likes
        Last Post ScottWalsh  
        Started by ScottWalsh, Today, 04:29 PM
        0 responses
        7 views
        0 likes
        Last Post ScottWalsh  
        Started by rtwave, 04-12-2024, 09:30 AM
        2 responses
        22 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Started by tsantospinto, 04-12-2024, 07:04 PM
        5 responses
        70 views
        0 likes
        Last Post tsantospinto  
        Working...
        X