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

indicator with 4 series but only 3 plots.

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

    indicator with 4 series but only 3 plots.




    people with nt,



    i'm having trouble with an indicator i'm trying to create.



    i am working on an indicator that uses 4 other indicators to make calculations, so i have defined 4 series for these values. however, i only want to plot 3 of those indicators, the fourth one is an oscillator with values that can range between 0 and 100 and i don't want to plot or include those values in the chart at all. i do use those values for calculations but i want to define something like no plot for that fourth series. ¿how can i do this? please provide an example.


    the indicators i am indeed plotting look like this:


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




    very well, regards.​

    #2
    Hello rtwave,

    To do that you would add three plots like you have shown. You can then use a Series<dobule> object to store data.

    If you need 4 series to use then you can use Series<double> which are not shown in the UI.



    A series works just like a plot with a bars ago and is used and assigned the same way its just not visual.

    You can then use the plots you added to replot and data from those series or other indicator values.

    JesseNinjaTrader Customer Service

    Comment


      #3



      NinjaTrader_Jesse,



      thanks.



      i'm gonna need more specific assistance with this matter. as far as i can tell, the structure you mentioned is exactly the structure i'm working with:




      protected override void OnStateChange()
      ...

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


      else if (State == State.DataLoaded)
      {
      indicator1 = indicator1(Close, Convert.ToInt32( ));
      indicator2 = indicator2(Close, Convert.ToInt32( ));
      indicator3 = indicator3(Close, Convert.ToInt32( ));
      indicator4 = indicator4(Close, Convert.ToInt32( ));


      }


      protected override void OnBarUpdate()
      {


      if (CurrentBars[0] < 4) return;


      indicator1[0] = indicator1[0];
      indicator2[0] = indicator2[0];
      indicator3[0] = indicator3[0];
      indicator4[0] = indicator4[0];




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

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

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

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





      that is the structure i'm working with and the indicator will compile but will not plot. it seems to me that nt is expecting the fourth plot to be defined, however, as i mentioned, this is an oscillator indicator that i don't want to include in the chart at all. ¿how can this be fixed?


      very well, thanks, regards.

      Comment


        #4
        Hello rtwave,

        In that example you are not using the plots correctly because the plot names are the same as your indicator names.

        In DataLoaded you should have something like:


        else if (State == State.DataLoaded)
        {
        EMA1 = EMA(12);​


        Then based on the public inputs for the plots you have you would have code like this:


        indicator1[0] = EMA1[0];
        JesseNinjaTrader Customer Service

        Comment


          #5


          NinjaTrader_Jesse,



          thanks, but no.



          the code i included is just a rough outline of the indicator i'm working with. i am indeed using different names for each private and public variable and using capitalization when it is indispensable.



          i have one other indicator that uses 4 moving averages, 4 series and 4 plots and that one will plot without problem. however, when there are less plots than series the indicators will compile but will not plot.


          possibly i will need to create a sample indicator to illustrate this problem i have been dealing with.

          Comment


            #6
            Hello rtwave,

            The only way we can provide help is if you provide accurate samples of the problem, I would highly suggest making a demo of the problem and attaching that instead of pseudocode.

            JesseNinjaTrader Customer Service

            Comment


              #7



              people with nt,



              this indicator i have attached will plot without problem. 4 indicators, 4 series, 4 plots.



              however, if one comments out any of the plots then this same indicator will not plot anymore. exact same thing, 4 indicators, 4 series, less than 4 plots and then it will not plot anything.


              this is what i have been referring to.



              i have some indicators the values for the which i want to use for calculations inside strategies or complex indicators, but i do not want to plot them all. ¿how can one include an indicator inside another indicator to use its values without having to plot all of them and the bigger construct will still be plotted?



              that is the situation.

              Attached Files

              Comment


                #8
                Hello rtwave,

                If you comment out any of the plots you would also need to comment out the code which was setting that plot and the public property for that plot in addition to updating the other public properties for the correct order of the plots. You are likely seeing an error in the log tab when trying to run the script.

                The script you provided has 4 public prperties which reference Values, for example:

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

                If you remove a plot and still have a public property for that plot its going to cause an error because there are less plots now. You need to match the number of public properties with the number of plots and make sure Values[X] corresponds to the plot you want that public property to use. The plots are indexed starting at 0, if you have 3 plots they will be 0,1,2 indexes.

                JesseNinjaTrader Customer Service

                Comment


                  #9


                  please provide an example for this " If you remove a plot and still have a public property for that plot its going to cause an error because there are less plots now. You need to match the number of public properties with the number of plots and make sure Values[X] corresponds to the plot you want that public property to use. "


                  and as i have stated multiple times, i do want to use all the series and-or the values, just not plot everything. i want to be able to use series for logical calculations but not have to plot every single one of them. that is the motivation.

                  Comment


                    #10
                    Hello rtwave,

                    Without knowing which plot you are removing it would be hard to make a specific sample. The way you need to edit the file changes depending on which plot is removed. We can quickly go over how plots and properties work and how you can also generate them using the platform.

                    When you use AddPlot that creates one plot and adds it to the Values collection: https://ninjatrader.com/support/help...ightsub=values

                    Code:
                    Values[PlotIndex]
                    Values is how you set a value to a plot.

                    A public property is a way to give Values[PlotIndex] a name so you don't need to remember what index each plot is.

                    Code:
                    [Browsable(false)]
                    [XmlIgnore]
                    public Series<double> Ema01
                    {
                        get { return Values[0]; }
                    }​
                    You can see in this property its named Ema01 and it returns Values[0] meaning the first AddPlot statement.

                    Going back to your sample, if you removed the 4th AddPlot you would comment out the public property that uses Values[3] which is Ema04. If you commented out the first AddPlot you would have to comment out 1 of the public properties and then fix the indexes used on the other 3 public properties so that the public property matches the plot it should go with. When you remove 1 AddPlot statement you now have 3 total series.


                    To simplify making this change I would suggest using the new indicator wizard to generate the plots and public properties you want, you can do the following steps to generate the code:
                    1. In the NinjaScript editor right click the indicator folder and create a new indicator.
                    2. In the wizard that opens use the Plots page to create the plots you want.
                    3. Generate the indicator and view the generated code.

                    At this point you can copy any public properties and AddPlot statements into another script that you are making, this ensures the correct indexes are used for the public properties. You can close the new indicator after you copy the properties and AddPlot statements to discard it.




                    and as i have stated multiple times, i do want to use all the series and-or the values, just not plot everything. i want to be able to use series for logical calculations but not have to plot every single one of them. that is the motivation.

                    You can't use a plot series without it being visual. If you need 3 plots and 1 hidden series you would make a private Series<double> instead of a Plot. I provided a link to a sample on how to do that in post 2.


                    JesseNinjaTrader Customer Service

                    Comment


                      #11


                      well, in the end i was able to program this indicator as intended. i can now use this knowledge to refine other indicators in the future.



                      indeed it was a matter of defining both plots and series in parallel and even when both tools serve pretty much the same function there are a lot of small differences between how each of them must be defined. it doesn't make much sense to have protocols so different from one another for two tools that are pretty much identical but it is what it is. and as far as i can tell there are no samples for the use of both plots and series in one same indicator, nt should create sample code for this kind of cases.

                      Comment


                        #12



                        i share the code for one sample indicator in case this could help someone at some point. this will plot an ema and also hold only the values for another ema. all values can be used for calculations and operations, however, only one of the emas will be plotted. this same structure can be used to define as many plots and series as needed.


                        Code:
                        
                        #region Using declarations
                        using System;
                        using System.Collections.Generic;
                        using System.ComponentModel;
                        using System.ComponentModel.DataAnnotations;
                        using System.Linq;
                        using System.Text;
                        using System.Threading.Tasks;
                        using System.Windows;
                        using System.Windows.Input;
                        using System.Windows.Media;
                        using System.Xml.Serialization;
                        using NinjaTrader.Cbi;
                        using NinjaTrader.Gui;
                        using NinjaTrader.Gui.Chart;
                        using NinjaTrader.Gui.SuperDom;
                        using NinjaTrader.Gui.Tools;
                        using NinjaTrader.Data;
                        using NinjaTrader.NinjaScript;
                        using NinjaTrader.Core.FloatingPoint;
                        using NinjaTrader.NinjaScript.DrawingTools;
                        #endregion
                        
                        //This namespace holds Indicators in this folder and is required. Do not change it.
                        namespace NinjaTrader.NinjaScript.Indicators
                        {
                            public class sampleindicator : Indicator
                            {
                        
                                private    EMA ema01;        
                                private Series<double> ema02;
                        
                        
                                protected override void OnStateChange()
                                {
                                    if (State == State.SetDefaults)
                                    {
                                        Description                                    = @"sampleindicator.";
                                        Name                                        = "sampleindicator";
                                        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;
                                        Emac01                    = 6;
                                        Emac02                    = 6;                                        
                                        AddPlot(new Stroke(Brushes.DarkGray, DashStyleHelper.Solid, 1), PlotStyle.Line, "ema01");
                        
                        
                                    }
                                    else if (State == State.Configure)
                                    {
                                    }
                                    else if (State == State.DataLoaded)
                                    {
                        
                                        ema01        = EMA(Emac01);
                                        ema02         = new Series<double>(this, MaximumBarsLookBack.TwoHundredFiftySix);
                        
                        
                                    }
                                }
                        
                                protected override void OnBarUpdate()
                                {
                        
                        
                                    Ema01[0]        = ema01[0];
                                    ema02[0]        = EMA(Close, Convert.ToInt32(Emac02))[0];
                        
                        
                                }
                        
                                #region Properties
                        
                                [NinjaScriptProperty]
                                [Range(1, int.MaxValue)]
                                [Display(Name="Emac01", Description="emac01.", Order=1, GroupName="Parameters.")]
                                public int Emac01
                                { get; set; }
                        
                                [NinjaScriptProperty]
                                [Range(1, int.MaxValue)]
                                [Display(Name="Emac02", Description="emac02.", Order=2, GroupName="Parameters.")]
                                public int Emac02
                                { get; set; }
                        
                                [Browsable(false)]
                                [XmlIgnore]
                                public Series<double> Ema01
                                {
                                    get { return Values[0]; }
                                }
                        
                                #endregion
                        
                            }
                        }
                        
                        ​

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by jaybedreamin, Today, 05:56 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post jaybedreamin  
                        Started by DJ888, 04-16-2024, 06:09 PM
                        6 responses
                        18 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Started by Jon17, Today, 04:33 PM
                        0 responses
                        4 views
                        0 likes
                        Last Post Jon17
                        by Jon17
                         
                        Started by Javierw.ok, Today, 04:12 PM
                        0 responses
                        12 views
                        0 likes
                        Last Post Javierw.ok  
                        Started by timmbbo, Today, 08:59 AM
                        2 responses
                        13 views
                        0 likes
                        Last Post bltdavid  
                        Working...
                        X