Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

trouble with public Series<double> versus addplot.

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

    trouble with public Series<double> versus addplot.





    people with nt,



    good day.



    i'm having trouble trying to create an indicator that will plot several indicators.


    i created an ema ribbon indicator with 7 emas that works well on nt 8. there are 7 public Series<double> series and 7 plots using addplot. the emas change colors according to some conditions and every ema is plotted on the chart.



    i am now trying to create an indicator that will only plot 5 emas but will also include other indicators that i only want to have as public Series<double> series to use their values for logical conditions. this means that there will be more series than plots. i don't see how this could be a problem and the indicator does compile successfully but then when i activate it on a chart nothing will be plotted.



    i confirmed the problem is generated by the disparity between series and plots by creating a copy of my ema ribbon indicator with 7 emas and removing the last 2 plots. there are 7 series and only 5 plots in this experimental version. everything seems fine but then ninjatrader won't plot anything when i activate this incomplete ema ribbon indicator on a chart.



    i took a look at the addplot and public series sections on the help guide but there is no helpful information. ¿how can i modify my code so that having more series than plots will not be a problem?



    very well, thanks, regards.

    #2
    Hello rtwave,

    Thanks for your post.

    An indicator object is already a Series<T> object. You could consider creating the indicator object at the class level, initializing the indicator object in OnStateChange when State == State.DataLoaded, and then you could use that indicator object in the conditions in your script. For example, see below.

    Code:
    //class level variables
    private SMA MySMA1;
    private EMA MyEMA1;
    
    //OnStateChange
    else if (State == State.DataLoaded)
    {
        MySMA1 = SMA(Close, 20);
        MyEMA1 = EMA(Close, 20);
    }
    
    protected override void OnBarUpdate()
    {
        Print("MySMA1: " + MySMA1[0]);
        Print("MyEMA1: " + MyEMA1[0]);
    }
    If this does not resolve your inquiry, please let us know and we will be happy to assist further. Also, please note the Log tab of the Control Center for any errors that might be occurring when running your script. If you see error messages occurring, let us know exactly what those error messages say.

    Let us know if we may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3





      NinjaTrader_BrandonH,



      i'm already doing all of that for every indicator i use.



      private EMA ema1;


      ema1 = EMA(Close, Convert.ToInt32(Period));



      Emas01[0] = ema1[0];


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


      AddPlot(new Stroke(Brushes.DarkGray, DashStyleHelper.Solid, 1), PlotStyle.Line, "ema1");



      if i'm using 7 emas, 7 public Series<double> series and 7 plots then the composite indicator will plot without problem.



      when i have 7 emas, 7 series and only 5 plots then nothing will be plotted. nt can create an indicator with multiple emas and then when removing one of the plots the same problems should be observed.


      ¿how can i fix this? i want to have 7 indicators to check for conditions and only plot 5 of those, the other 2 should only be processed as series.

      Comment


        #4
        Hello rtwave,

        Thanks for your note.

        When running your script, do you see any errors occurring in the Log tab of the Control Center?

        If so, what exactly do those errors report?

        I look forward to assisting further.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5


          NinjaTrader_BrandonH,



          i created a version of the indicator without any additional logic.


          as it is below it won't plot. if one restores the 2 plots that are commented out, the thing will plot without problem.


          //This namespace holds Indicators in this folder and is required. Do not change it.
          namespace NinjaTrader.NinjaScript.Indicators
          {
          public class emaribboninc : Indicator
          {

          private EMA ema01;
          private EMA ema02;
          private EMA ema03;
          private EMA ema04;
          private EMA ema05;
          private EMA ema06;
          private EMA ema07;


          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          Description = @"emaribboninc.";
          Name = "emaribboninc";
          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;
          Emal01 = 5;
          Emal02 = 10;
          Emal03 = 15;
          Emal04 = 20;
          Emal05 = 25;
          Emal06 = 30;
          Emal07 = 35;
          AddPlot(new Stroke(Brushes.DarkGray, DashStyleHelper.Solid, 1), PlotStyle.Line, "ema01");
          AddPlot(new Stroke(Brushes.DarkGray, DashStyleHelper.Solid, 1), PlotStyle.Line, "ema02");
          AddPlot(new Stroke(Brushes.DarkGray, DashStyleHelper.Solid, 1), PlotStyle.Line, "ema03");
          AddPlot(new Stroke(Brushes.DarkGray, DashStyleHelper.Solid, 1), PlotStyle.Line, "ema04");
          AddPlot(new Stroke(Brushes.DarkGray, DashStyleHelper.Solid, 1), PlotStyle.Line, "ema05");
          // AddPlot(new Stroke(Brushes.DarkGray, DashStyleHelper.Solid, 1), PlotStyle.Line, "ema06");
          // AddPlot(new Stroke(Brushes.DarkGray, DashStyleHelper.Solid, 1), PlotStyle.Line, "ema07");

          }
          else if (State == State.Configure)
          {
          }
          else if (State == State.DataLoaded)
          {
          ema01 = EMA(Emal01);
          ema02 = EMA(Emal02);
          ema03 = EMA(Emal03);
          ema04 = EMA(Emal04);
          ema05 = EMA(Emal05);
          ema06 = EMA(Emal06);
          ema07 = EMA(Emal07);

          }
          }

          protected override void OnBarUpdate()
          {
          //Add your custom indicator logic here.
          Emav01[0] = ema01[0];
          Emav02[0] = ema02[0];
          Emav03[0] = ema03[0];
          Emav04[0] = ema04[0];
          Emav05[0] = ema05[0];
          Emav06[0] = ema06[0];
          Emav07[0] = ema07[0];



          }

          #region Properties

          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name="Emal01", Description="emal01.", Order=1, GroupName="Parameters")]
          public int Emal01
          { get; set; }

          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name="Emal02", Description="emal02.", Order=2, GroupName="Parameters")]
          public int Emal02
          { get; set; }

          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name="Emal03", Description="emal03.", Order=3, GroupName="Parameters")]
          public int Emal03
          { get; set; }

          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name="Emal04", Description="emal04.", Order=4, GroupName="Parameters")]
          public int Emal04
          { get; set; }

          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name="Emal05", Description="emal05.", Order=5, GroupName="Parameters")]
          public int Emal05
          { get; set; }

          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name="Emal06", Description="emal06.", Order=6, GroupName="Parameters")]
          public int Emal06
          { get; set; }

          [NinjaScriptProperty]
          [Range(1, int.MaxValue)]
          [Display(Name="Emal07", Description="emal07.", Order=7, GroupName="Parameters")]
          public int Emal07
          { get; set; }



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

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

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

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

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

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

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

          #endregion

          }
          }



          and yes, there's an error in the log:



          Time Category Message
          06-Apr-22 16:35:42 Default Indicator 'emaribboninc': Error on calling 'OnBarUpdate' method on bar 0: Index was outside the bounds of the array.

          Comment


            #6
            Hello rtwave,

            Thanks for your note.

            The error in the Log tab of the Control Center is related to Values not containing a plot. The following properties become invalid if you comment out the AddPlot() calls for them.

            Code:
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> Emav06
            {
            get { return Values[5]; }
            }
            
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> Emav07
            {
            get { return Values[6]; }
            }
            You would either need the same number of AddPlot() calls as the Values being used in the script. For example, if you have 5 AddPlot() calls then you would need to comment out the above properties. Otherwise, you would need to have all 7 AddPlot() calls in the script.

            Let us know if we may assist further.
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7



              NinjaTrader_BrandonH,



              i did as you suggest and then the file will not compile.


              NinjaScript File Error Code Line Column
              emaribboninc.cs The name 'Emav06' does not exist in the current context CS0103 96 4




              ¿how can i define those 2 Emav06 and Emav07 values in a way that it won't be necessary to plot them? i'm using other indicators and calculations that cannot be plotted on a chart.



              when creating strategies it is possible to have as many indicators as one wants to and without plotting any of them. this must mean that it must be possible to use series - values - indicators inside an indicator without having to plot them.



              i provided an example previously in this thread. ¿how can the code i posted before be fixed so that the indicator can have 7 emas with only 5 of them being plotted?



              Comment


                #8
                Hello rtwave,

                Thanks for your note.

                You cannot have fewer AddPlot() calls in your script than Values in the properties section. If you have 7 Values in your script then you would also need to call AddPlot() 7 times.

                Otherwise, you could comment out the Values mentioned in my previous post and also comment out 'Emav06[0] = ema06[0];' and 'Emav07[0] = ema07[0];' from your script.

                Something you could consider is leaving the 7 AddPlot() calls in your script and setting the 'ema06' and 'ema07' plots to Transparent. That way 5 of the 7 plots will display on the chart window.

                Code:
                AddPlot(new Stroke(Brushes.Transparent, DashStyleHelper.Solid, 1), PlotStyle.Line, "ema06");
                AddPlot(new Stroke(Brushes.Transparent, DashStyleHelper.Solid, 1), PlotStyle.Line, "ema07");
                You could also consider creating a custom Series<double> variable and assigning the EMA indicator value to that custom series. For example, see below.

                Code:
                //class level variable
                private Series<double> ema06;
                
                else if (State == State.DataLoaded)
                {
                    ema06 = new Series<double>(this);
                }
                
                protected override void OnBarUpdate()
                {
                    ema06[0] = EMA(Emal06)[0];
                }
                See this help guide for information about working with custom Series<double> objects: https://ninjatrader.com/support/help...t8/seriest.htm

                Let us know if we may assist further.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment


                  #9



                  NinjaTrader_BrandonH,




                  i have been able to figure this out.



                  i had been using the series like Emav01[0] (in the code i posted previously) to evaluate logical conditions. therefore it seemed to me like i needed to define one of these series for every indicator i wanted to use. however, there are some indicators that i want to plot and some that i only want to use to evaluate.



                  i took a look at some strategies i have developed and realized that it is series like ema01[0] that i should be using. i have now changed all my indicators that include multiple indicators and they work correctly. i will now define series like Emav01[0] only for the indicators i would want to have plotted and can have as many indicators inside another indicator as i wish to.



                  i share my results for anyone who could have a similar problem.




                  very well, regards.

                  Comment

                  Latest Posts

                  Collapse

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