Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plots Collection, accessing element by property, not ordinal

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

    Plots Collection, accessing element by property, not ordinal

    In Help Guide > NinjaScript > Language Reference > Indicator > Plots

    After adding a plot,
    Add(new Plot(Color.Orange, "Plotypus") );

    it shows to access the element in the Plots collection using it's ordinal value, i.e. Plots[0]

    Isn't there a way to access the Plot in the Plots collection by using the "name" parameter when the plot was added?
    i.e. Plots["Plotypus"]
    or
    Plots.Name("Plotypus")

    It seems prone to errors if you are relying on the ordinal access based on how new items are added to the collection, if some code changes in the future and the order changes. Of course the same risk would apply if access the collection element by it's name property if the name value was changed in code.

    #2
    Originally posted by balltrader View Post
    In Help Guide > NinjaScript > Language Reference > Indicator > Plots

    After adding a plot,
    Add(new Plot(Color.Orange, "Plotypus") );

    it shows to access the element in the Plots collection using it's ordinal value, i.e. Plots[0]

    Isn't there a way to access the Plot in the Plots collection by using the "name" parameter when the plot was added?
    i.e. Plots["Plotypus"]
    or
    Plots.Name("Plotypus")

    It seems prone to errors if you are relying on the ordinal access based on how new items are added to the collection, if some code changes in the future and the order changes. Of course the same risk would apply if access the collection element by it's name property if the name value was changed in code.
    Use STATIC INTS?

    That should help...

    Code:
    		static 	int ES  = 0;
    		static 	int VIX = 1;
    
    
    
    
    				Print ( ToDay (Time[0]) + "," + ToTime(Time[0]) + ",ES," + "Flat: " + Closes[ES][0]  );
    				Print ( ToDay (Time[0]) + "," + ToTime(Time[0]) + ",VIX," + "Flat: " + Closes[VIX][0]  );

    Comment


      #3
      balltrader,

      Are you looking for Plotypus[0] for example? Or are you looking for what sledge suggested?
      Patrick H.NinjaTrader Customer Service

      Comment


        #4
        @sledge, thanks for reply, but I'm not understanding what you are trying to show me.

        If you are demonstrating how to use a var type INT to replace an INT inside a CLOSE arg, no that's not what I meant sorry.

        Comment


          #5
          @Pat

          Platy[0] is closer, but ...

          i.e. Plots["Plotypus"]
          or
          Plots.Name("Plotypus")

          I'm mostly just wondering why the PLOTS collection doesn't allow this as a default method of accessing the element in the PLOTS collection

          Comment


            #6
            So you wish to pull the name of the plot?
            Patrick H.NinjaTrader Customer Service

            Comment


              #7
              yes. to be able to access the plot object in the collection by using it's name parameter

              Comment


                #8
                balltrader,

                I may still not follow you here, but you can pull the name of the plot with Plots[0].Name.ToString(). Is this what you are looking for? I guess you are trying to access values at specific barsAgo indexes using the name?
                Patrick H.NinjaTrader Customer Service

                Comment


                  #9
                  Sorry to resurrect this old post, but I have some new information now form the NT8 help guide on AddPlot.

                  The help guide says when an AddPlot is used, a series<t> is auto created and can be accessed via get Values[0] and set Values[0][0] = 4.0;

                  It says the Plot object doesn't hold actual values. I think I understand this to mean the Plot object, is only holding attributes of the line, ie brush, color, thickness etc. and when the line is rendered, it gets the coordinates from the Values[0] series. But I don't find anywhere that this is described, so I am only guessing, is my assumption on how this works correct? Is there a link to anywhere that this is explained?



                  Going back to my original point, I want to be able to get and set the "value" of the series, by using a descriptive name that is assigned to the plot, instead of using an abstraction of Values[0]

                  Example:
                  AddPlot ("MySMA") // plot is named MySMA

                  Now I want to set the value of the series used by the plot, by this psuedocode:
                  MySMA[x] = 4.0;

                  Is there a C# programming construct that would allow me to access the Values[0] series by using an alias of MySMA ?

                  Comment


                    #10
                    i think I may have figured it out. (NT8)

                    in my class, region "Variables"
                    i create a private var of type Series<double> named "Fxseries"
                    Code:
                       private Series<double> Fxseries;
                    in OnStateChange, State.DataLoaded
                    i assign the Values[0] series object instance to my var Fxseries
                    Code:
                       Fxseries = Values[0];
                    (note the series Values[0] was created in State.SetDefaults during the call to AddPlot() )

                    in OnBarUpdate

                    I can set the value of the Values[0] series by using the private variable name Fxseries
                    Code:
                        Fxseries[x] = 4.0;
                    This is better for me, as it is descriptive of what I am doing, and less prone to errors and makes the code much easier to read.

                    This works on a chart.

                    Please comment if this is not good, or if there is a better concept to implement this...

                    Thank you.
                    Last edited by balltrader; 10-19-2017, 06:41 AM.

                    Comment


                      #11
                      Oops I just realized this thread was started in the NT7 category, and I'm posting code for NT8

                      Comment


                        #12
                        Hello balltrader,

                        Thank you for your post.

                        You are correct on the AddPlot() item in the Help Guide. Plots would control the visual aspect and AddPlot() creates a Series<t> object to hold it's values.

                        A simplified means to use the object name to set it's value can be viewed below.

                        Please let me know if you have any questions.
                        Code:
                        		protected override void OnStateChange()
                        		{
                        			if (State == State.SetDefaults)
                        			{
                        				Description									= @"Enter the description for your new custom Indicator here.";
                        				Name										= "MyCustomIndicator";
                        				Calculate									= Calculate.OnBarClose;
                        				
                        				AddPlot(Brushes.Orange, "Test");
                        			}
                        		}
                        
                        		protected override void OnBarUpdate()
                        		{
                        			Test[0] = Close[0];
                        		}
                        
                        		#region Properties
                        
                        		[Browsable(false)]
                        		[XmlIgnore]
                        		public Series<double> Test
                        		{
                        			get { return Values[0]; }
                        		}
                        		#endregion
                        Patrick H.NinjaTrader Customer Service

                        Comment


                          #13
                          Thanks.
                          Questions:

                          1.
                          A.
                          For my understanding, by using the Properties region, the variable is created, (therefore I don't need to declare it in the class variables region?)

                          B.
                          In the Properties region, the variable is linked to the Values[0] object,(therefore I don't need to link it in the State.DataLoaded region?)

                          2.
                          In #region Properties, does the series need to be public, so the OBU method can read & write to it?

                          3.
                          In OnBarUpdate, you are assigning Test[0] = Close[0]
                          BUT, isn't that already being done in the property region?
                          In my example, I use OBU to set the value of Test[0] to a double numerical value.
                          I'm a little confused by that line.

                          Comment


                            #14
                            Hello balltrader,

                            Thank you for your response.

                            1. You are correct on both points A and B.
                            2. This is correct as well.
                            3. This line is just a basic example. However, nowhere else if the Plot being set to the Close of the bar. Here I am setting the Series<double> for the Plot to the Close of the bar.

                            Please let me know if you have any questions.
                            Patrick H.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by WHICKED, Today, 09:05 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post WHICKED
                            by WHICKED
                             
                            Started by luislag14, Today, 06:29 PM
                            0 responses
                            8 views
                            0 likes
                            Last Post luislag14  
                            Started by Protech, Today, 11:08 AM
                            1 response
                            23 views
                            0 likes
                            Last Post NinjaTrader_ChrisL  
                            Started by guilhem, Today, 02:09 PM
                            1 response
                            23 views
                            0 likes
                            Last Post NinjaTrader_BrandonH  
                            Started by Hyper, Today, 12:20 PM
                            1 response
                            23 views
                            0 likes
                            Last Post NinjaTrader_Jim  
                            Working...
                            X