Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error : Added Plots or Lines must have a unique name

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

    Error : Added Plots or Lines must have a unique name

    Hello
    I am discovering your platform and am faced with a difficulty that I cannot resolve with the error message:
    Error on calling 'OnStateChange' method: Added Plots or Lines must have a unique name.
    However, when reading my code, everything seems correct to me while only "band_bottom" value is displayed in Bnd_Top[ !
    Please explain to me where the problem is:​

    Code:
    protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    ...
                    AddPlot(Brushes.Yellow, "Bnd_Top");
                    AddPlot(Brushes.Blue, "Bnd_Bottom");​
    Code:
    protected override void OnBarUpdate()
            {
                if (CurrentBar < 51)
                    return;
    
                double band_top = -9999999999;
                double band_bottom = 9999999999;
                
                for (int i = 1; i < 5; i++)
                {
                    int z = periode_ema + (i * 3);
                    double emaValue = EMA(Open, z)[0];
                    
                    if (emaValue > band_top)
                    {
                        band_top = emaValue;
                    }
                    if (emaValue < band_bottom)
                    {
                        band_bottom = emaValue;
                    }
                }
                Print(Time[0]+"     "+band_top +"     "+band_bottom);
                Bnd_Top[0] = band_top;
                Bnd_Bottom[0] = band_bottom;
            }
    
    #region Properties
    
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> Bnd_Top
            {
                get { return Values[0]; }
            }
            
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> Bnd_Bottom
            {
                get { return Values[0]; }
            }
    
    
            #endregion​
    ​


    Thank you for your help
    Last edited by noabai; 11-08-2024, 07:59 AM. Reason: translated by google and not in my bad english

    #2
    Hello naobai,

    Thank you for your inquiry.

    Are these the only Plots or Lines added to this script?

    Does the error reference a specific indicator, and if so, is the code listed here from the indicator referenced in the error?

    I look forward to assisting further.

    Comment


      #3
      Thank you for your interest.
      I changed the name of my script from AAA to AA, recompiled and the error message disappeared but the display is still incorrect.
      There is no reference or other error message.
      The logic is good and the data calculated and displayed with the print are correct. It is only a display problem on the chart and I do not understand it...
      So I put the code (except the using)​
      Code:
      //This namespace holds Indicators in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Indicators
      {
          public class AA : Indicator
          {
              private int periode_ema = 6;
            
              
              protected override void OnStateChange()
              {
                  if (State == State.SetDefaults)
                  {
                      Description                                    = @"Enter the description for your new custom Indicator here.";
                      Name                                        = "AA";
                      Calculate                                    = Calculate.OnBarClose;
                      IsOverlay                                    = true;
                      DisplayInDataBox                            = true;
                      DrawOnPricePanel                            = true;
                      DrawHorizontalGridLines                        = true;
                      DrawVerticalGridLines                        = true;
                      PaintPriceMarkers                            = true;
                      ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                      //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                      //See Help Guide for additional information.
                      IsSuspendedWhileInactive                    = true;
                      AddPlot(Brushes.Yellow, "Bnd_Top");
                      AddPlot(Brushes.Blue, "Bnd_Bottom");
                  }
                  else if (State == State.Configure)
                  {
                  }
              }
      
              protected override void OnBarUpdate()
              {
                  if (CurrentBar < 51)
                      return;
      
                  double band_top = -9999999999;
                  double band_bottom = 9999999999;
                  
                  for (int i = 1; i < 14; i++)
                  {
                      int z = periode_ema + (i * 3);
                      double emaValue = EMA(Open, z)[0];
                      
                      if (emaValue > band_top)
                      {
                          band_top = emaValue;
                      }
                      if (emaValue < band_bottom)
                      {
                          band_bottom = emaValue;
                      }
                  }
                  Print(Time[0]+"     "+band_top +"     "+band_bottom);
                  Bnd_Top[0] = band_top;
                  Bnd_Bottom[0] = band_bottom;
              }
      
              #region Properties
      
              [Browsable(false)]
              [XmlIgnore]
              public Series<double> Bnd_Top
              {
                  get { return Values[0]; }
              }
              
              [Browsable(false)]
              [XmlIgnore]
              public Series<double> Bnd_Bottom
              {
                  get { return Values[0]; }
              }
      
      
              #endregion
      
          }
      }
      
      #region NinjaScript generated code. Neither change nor remove.
      
      namespace NinjaTrader.NinjaScript.Indicators
      {
          public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
          {
              private AA[] cacheAA;
              public AA AA()
              {
                  return AA(Input);
              }
      
              public AA AA(ISeries<double> input)
              {
                  if (cacheAA != null)
                      for (int idx = 0; idx < cacheAA.Length; idx++)
                          if (cacheAA[idx] != null &&  cacheAA[idx].EqualsInput(input))
                              return cacheAA[idx];
                  return CacheIndicator<AA>(new AA(), input, ref cacheAA);
              }
          }
      }
      
      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
          public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
          {
              public Indicators.AA AA()
              {
                  return indicator.AA(Input);
              }
      
              public Indicators.AA AA(ISeries<double> input )
              {
                  return indicator.AA(input);
              }
          }
      }
      
      namespace NinjaTrader.NinjaScript.Strategies
      {
          public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
          {
              public Indicators.AA AA()
              {
                  return indicator.AA(Input);
              }
      
              public Indicators.AA AA(ISeries<double> input )
              {
                  return indicator.AA(input);
              }
          }
      }
      
      #endregion
      ​

      Comment


        #4
        region Properties

        [Browsable(false)]
        [XmlIgnore]
        public Series<double> Bnd_Top
        {
        get { return Values[0]; }
        }

        [Browsable(false)]
        [XmlIgnore]
        public Series<double> Bnd_Bottom
        {
        get { return Values[1]; }
        }


        #endregion​

        Make the change in red above.
        eDanny
        NinjaTrader Ecosystem Vendor - Integrity Traders

        Comment


          #5
          Can you please provide more details about the "display" issue you are having? What is not being displayed correctly - is it in regards to your parameters?

          If so, please note that in your code in the Properties region both Bnd Bottom and Bnd Top and returning Values[0] which will cause them to display the same value. One should return Values[0] and another Values[1].

          Comment


            #6
            eDanny : Thanks for your reply, I understood that I had to index the series. I am discovering NT8 and C# and computers in general and it is not always very obvious to me

            Comment

            Latest Posts

            Collapse

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