Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Failed to call method 'Initialize' for indicator

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

    Failed to call method 'Initialize' for indicator

    Hi,

    I'm stumped with a rather odd problem.

    My indicator runs fine, with no error messages when applied to charts.

    However, when I set it as one of the columns in Market Analyzer, the following error message appears in the Log:

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

    I'm really at a loss to explain why the error message only pops up when used in MA, but not when applied to charts. The indicator itself works fine (in both instances) as far as I can tell.

    Any suggestions?

    Regards,
    Nick

    #2
    Hi Nick,

    Do you have access to the source code of this indicator?

    You should be able to isolate this error message in the indicator to a single line just by removing/commenting out everything in the Initialize method.

    Once you've isolated the offending lines, we can look into why that particular call is failing in one environment and another the other.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Nailed it.

      This was the offending line of code, if any others were curious:

      if (Instrument.MasterInstrument.InstrumentType == InstrumentType.Stock && BarsPeriod.Id != PeriodType.Day)

      -Nick

      Comment


        #4
        Failed to call method 'Initialize' for indicator 'Correlation'

        Hello guys. I get this message when test indicator Correlation (http://www.ninjatrader.com/support/f...tid=-1&lpage=1)
        Failed to call method 'Initialize' for indicator 'Correlation': 'Add' method only accepts positive 'period' values, but was -1 Min

        I tried to run this in strategy in Strategy Analyzer with EOD data.

        Code:
        protected override void Initialize()
         {
        Add(MyInstrum2,PeriodType.Day,1);
        Add(Correlation(Closes[0],CorrelationType.Pearson,14,1,MyInstrum2));
        Correlation(Closes[0],CorrelationType.Pearson,14,1,MyInstrum2).Panel=3;
        Correlation(Closes[0],CorrelationType.Pearson,14,1,MyInstrum2).ScaleJustification=ScaleJustification.Right;
        ...............................
        if (Correlation(Closes[0],CorrelationType.Pearson,14,1,MyInstrum2)[0]>0)
        buy...

        Comment


          #5
          Hello alexstox,

          Thank you for your post.

          Likely the cause of this is the following line in the Correlation indicator:
          Code:
          Add(Symbol2, BarsPeriod.Id, BarsPeriod.Value);
          Using BarsPeriod.Id and BarsPeriod.Value in Initialize() can have unexpected results and it is not recommended to use these in the Initialize() method as the bars are likely to not have loaded fully in Initialize(). Please contact the developer of the indicator for further assistance.

          Comment


            #6
            Originally posted by NinjaTrader_PatrickH View Post
            Hello alexstox,

            Thank you for your post.

            Likely the cause of this is the following line in the Correlation indicator:
            Code:
            Add(Symbol2, BarsPeriod.Id, BarsPeriod.Value);
            Using BarsPeriod.Id and BarsPeriod.Value in Initialize() can have unexpected results and it is not recommended to use these in the Initialize() method as the bars are likely to not have loaded fully in Initialize(). Please contact the developer of the indicator for further assistance.
            Patrick, what can I replace it with?

            Comment


              #7
              Hello alexstox,

              Thank you for your response.

              You could replace it with the direct information of the chart you plan to use it on. For example a 1 Minute chart: Add(Symbol2, PeriodType.Minute, 1);

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              88 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              48 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              31 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              34 views
              0 likes
              Last Post TheRealMorford  
              Started by Mindset, 02-28-2026, 06:16 AM
              0 responses
              69 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Working...
              X