Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error with custom indicator

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

    Error with custom indicator

    I've looked at a couple of custom indicators and they work fine with 6.5 and compile with no error with NT7. When loading the indicator on a chart, I get an error in the log:
    Failed to call method 'Initialize' for indicator xyz. 'BarsInProgress' property can not be accessed from within 'Initialize' method

    Don't have BarsInProgress in Intialize. Any ideas what may be wrong?

    -thanks

    #2
    Originally posted by laparker View Post
    I've looked at a couple of custom indicators and they work fine with 6.5 and compile with no error with NT7. When loading the indicator on a chart, I get an error in the log:
    Failed to call method 'Initialize' for indicator xyz. 'BarsInProgress' property can not be accessed from within 'Initialize' method

    Don't have BarsInProgress in Intialize. Any ideas what may be wrong?

    -thanks
    Can you paste in your code in Initialize()? Likely accessing some property/method that is internally calling BarsInProgress etc...Would want to see what that might be so we can provide a resolution.
    RayNinjaTrader Customer Service

    Comment


      #3
      This is the Initialize section from the indicator code:



      Code:
      /// <summary>
              /// This method is used to configure the indicator and is called once before any bar data is loaded.
              /// </summary>
              protected override void Initialize()
              {
                  Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "RisingPlot") );
                  Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "FallingPlot") );
                  Add(new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "NeutralPlot"));
                  CalculateOnBarClose    = true;
                  Overlay                = true;
                  PriceTypeSupported    = false;
                  
                  Plots[0].Pen.Width = 2;
                  Plots[1].Pen.Width = 2;
                  Plots[2].Pen.Width = 2;
                  
                  dmv = new DataSeries(this);
                  signal = new DataSeries(this);
                  lastDirection = -2;
                  double double1 = TickSize;
                  int max = 30;
                  int i = 0;
                  while (double1 % 1 !=0 )
                  {
                      double1 *= 10;
                      decimals++;
                      i++;
                      if( i > max )
                          break;
                  }
                  if( decimals > 0 )
                      decimals++;
              }
      
              /// <summary>

      Comment


        #4
        a) Are you sure you are on NT6B2? There was an issue with PriceTypeSupported on B1.
        b) Anything in the logs?

        Comment


          #5
          a) Are you sure you are on NT6B2? There was an issue with PriceTypeSupported on B1.
          b) Anything in the logs?
          Don't know about a) but am running NT7
          and b) the log says:
          2009-10-19 15:37:02:859 ERROR: Failed to call method 'Initialize' for indicator 'DoubleMA': 'BarsInProgress' property can not be accessed from within 'Initialize' method

          Comment


            #6
            >> Don't know about a) but am running NT7
            Please see Help->About, should read 7.0.0.2. If not then you needed to update.

            Comment


              #7
              yup, it's 7.0.0.2

              Comment


                #8
                Can you try commenting out the PriceTypeSupported line and trying again?
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Also: I suspect "TickSize" might be problem.

                  Note: Using TickSize in Initialize() really does not make sense, since at the time Initialize() is executed there is no instrument selected yet and thus no TickSize available yet. I believe NT6.5 might have "faked" in 0.01 in that situation.

                  Comment


                    #10
                    It looks like TickSize was the issue. I've changed the variable to initialize with 0.01 and it seems to now work. Commenting out the PriceTypeSupported line made no difference. I have another indicator with PriceTypeSupported = true and there looks like there could be an issue there. I will try hard coding the price type to Close and see what happens.

                    -thanks

                    Comment


                      #11
                      To clarify, PriceTypeSupported should be working again. If you find otherwise, please let us know. Thank you.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        In the Initialize() section I have PriceTypeSupported = true and am referencing Input - eg
                        Code:
                        avg = HMA(Input, smooth);
                        but am not getting the input display in the parameters dialogue to set the price type.

                        Comment


                          #13
                          This would be set under data > input series in NinjaTrader 7, you can expand this and choose the input series for your HMA...

                          Comment


                            #14
                            This would be set under data > input series in NinjaTrader 7, you can expand this and choose the input series for your HMA...
                            ok, got it - thanks.

                            However this other indicator still doesn't work so there must be something else upsetting it in the Initialize() section. Here is that section:

                            Code:
                              protected override void Initialize()
                                    {
                                        Add(new Plot(Color.Green, PlotStyle.Hash, "UpTrend"));
                                        Add(new Plot(Color.Red, PlotStyle.Hash, "DownTrend"));
                                        CalculateOnBarClose = true;
                                        Overlay = true;
                                        PriceTypeSupported = true;        
                                        trend = new BoolSeries(this);
                                        if(smooth > 1)
                                            switch (maType) 
                                            {
                                                case MovingAverageType.SMA:
                                                    avg = SMA(Input, smooth);
                                                    break;
                                                case MovingAverageType.SMMA:
                                                    avg = SMMA(Input, smooth);
                                                    break;
                                                case MovingAverageType.TMA:
                                                    avg = TMA(Input, smooth);
                                                    break;
                                                case MovingAverageType.WMA:
                                                    avg = WMA(Input, smooth);
                                                    break;
                                                case MovingAverageType.VWMA:
                                                    avg = VWMA(Input, smooth);
                                                    break;
                                                case MovingAverageType.TEMA:
                                                    avg = TEMA(Input, smooth);
                                                    break;
                                                case MovingAverageType.HMA:
                                                    avg = HMA(Close, smooth);
                                                    break;
                                                case MovingAverageType.VMA:
                                                    avg = VMA(Input, smooth, smooth);
                                                    break;
                                                default:
                                                    avg = EMA(Input, smooth);
                                                    break;
                                            } else 
                                                avg = Input;
                                    }

                            Comment


                              #15
                              I think the switch needs to go into the OnBarUpdate() with an enum in the properties, see the SampleUniversalMA for the coding structure.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              635 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              364 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              106 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              567 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              571 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X