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

Locate Plot associated with a DataSeries

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

    Locate Plot associated with a DataSeries

    Hi all

    I'm trying to figure out how to access a plot that is associated with a given DataSeries.
    NT has to be storing a relationship for them somewhere.

    ie
    during Initialize the following occurs: Add(new Line(Color.FromKnownColor(KnownColor.Black), 0, "myData"));

    Then during OnBarUpdate I want to be able to locate the Plot starting with a reference to myData.

    #2
    Hello,

    Thank you for the question.

    For lines you can see this document which has an example on how you would update a line from the OnBarUpdate()



    This is a simple way of accessing the line plots from the Lines collection.

    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks Jesse.

      Close, but not what I'm looking for.

      I want to get to the graphic components directly from the named dataseries.
      The way you reference doesn't accomplish that.

      I want to do something like:

      myData.Plots.Pen.Width = 3;
      or something close to that without having to remember which subscript and plottype to reference.

      Comment


        #4
        Hello,

        If you want to add a variable name for a specific line you would do so just as you do with a Plot. Here is an example:

        Code:
        protected override void Initialize()
        {
            Add(new Line(Color.Red, 1, "TheLine"));
        }
        
        [Browsable(false)]
        [XmlIgnore()]	
        public Line TheLine
        {
             get { return Lines[0]; }
        }
        
        protected override void OnBarUpdate()
        {
             TheLine.Value = Close[0];
             TheLine.Pen.Width = 5;
        }
        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          That's better.
          Thanks

          But, doesn't NT somewhere, somehow, maintain a relationship between the dataseries and the graphic components other than a subscript?

          Comment


            #6
            Hello,

            Can you please clairify the question?

            The relationship between the "named" line and Line would be the public property

            [Browsable(false)]
            [XmlIgnore()]
            public Line TheLine
            {
            get { return Lines[0]; }
            }

            The Line which is at index 0 of the Lines collection would be referenced using this property, Generally you will find this in the #region Properties section of a script.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              You manually added the public property, right?

              Once I Add TheLine, I have a Line property and a Dataseries property.
              Behind the scenes, how does NT know that the Line I added relates to the DataSeries of the same name?

              If I do a TheLine.Set(Close[0]); and then a Lines[0].Pen.Color = Color.Red, somehow NT knows that these two are related when it draws on the window. Dataseries must somehow have a pointer to the Line object.

              What if I were doing a ForEach loop on the dataseries and wanted to manipulate the graphic, there must be a way to get to there.

              Comment


                #8
                Hello,

                Yes the Public property you need to add for this link to occur otherwise you would have to call it by its index value which would be the order in which it was added.

                So with the public property:
                Code:
                protected override void Initialize()
                {
                    Add(new Line(Color.Red, 1, "TheLine"));
                }
                
                [Browsable(false)]
                [XmlIgnore()]	
                public Line TheLine
                {
                     [B]get { return Lines[0]; }[/B] //this is the link, the returned values of Lines[0]
                }
                
                protected override void OnBarUpdate()
                {
                     TheLine.Value = Close[0];
                     TheLine.Pen.Width = 5;
                }
                and without the public property:

                Code:
                protected override void Initialize()
                {
                    Add(new Line(Color.Red, 1, "TheLine"));
                }
                
                protected override void OnBarUpdate()
                {
                     Lines[0].Value = Close[0];
                     Lines[0].Pen.Width = 5;
                }
                The major difference would be where you return the Lines[0] object, this allows you to call the variable name and it is equal to the lines object. This contains its values, pen, etc..
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  OK. Thanks.

                  So, if I were doing a ForEach over the DataSeries I would not be able to access the related drawing objects?

                  Comment


                    #10
                    Hello,

                    Drawing objects would be different than this specifically. This works similar to a plot in just adding a horizontal line, a drawing object is slightly different. It can be either script drawn or user drawn and is stored in a collection.

                    The code below shows how to loop through the drawing objects to identify a specific object.

                    Code:
                    foreach (IDrawObject draw in DrawObjects)
                    {
                         if(draw.UserDrawn)
                         {
                               //drawn by the user     
                               Print(draw.DrawType.ToString()); //you can get the tag of the object to help narrow down results
                               if(draw.DrawType == DrawType.Ray) //if the object type is a ray do this
                               {
                                    IRay ray = draw as IRay; //need to re define the IDrawingObject as a Ray to access the correct values
                                     Print(ray.Anchor1Y); //now ray has all of the Ray methods.
                               }
                         } else {
                                     //drawn by NinjaScripting     
                         }
                    }
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks.

                      However, that iterates the DrawObjects, not the DataSeries.

                      Comment


                        #12
                        Hello,

                        I posted this as this would be the correct way to look for drawing objects from NinjaScript, they are not held in the DataSeries. Data series hold price data and not drawing objects.
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          Thanks.

                          Then how do the DataSeries and DrawingObjects know about each other?

                          Comment


                            #14
                            Hello,

                            If you think of it this way,
                            Your chart holds all of your data series in a collection.
                            The chart also holds all of the drawing objects in a collection,
                            these are both housed in the same chart.

                            With this information we now know that any drawing object added to this specific chart, regardless of the indicator that has added it or if a user has added this drawing object, it will be available in the drawing objects collection.

                            The chart its self is holding multiple collections of items in which you can access from this chart and this chart only. Being that the chart is the scope for the indicator or strategy there is no cross references from other charts, everything is encapsulated at the chart level.

                            I look forward to being of further assistance.
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              Thanks. That all makes sense.

                              The chart holds a collection of DrawObjects and collection DataSeries.

                              DataSeries objects don't contain a pointer to a DrawObject.

                              These are the things I understand from our discussion.

                              If in my chart I have a dataseries of price values and I have a DrawObject of, say, SMA. All added from the chart interface. (no user coding)

                              Now when my chart updates the DataSeries it updates the bar on my chart window and it updates the SMA graphic.

                              How does the SMA know it needs to update and how does it get the value(s) for it's computation?
                              Either the DataSeries has a collection of attached DrawObjects or the DrawObjects has a pointer to a DataSeries. Or, there is a 3rd object I haven't found yet that establishes these relationships.

                              Make sense?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by funk10101, Today, 08:14 AM
                              3 responses
                              4 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by frankthearm, Today, 09:08 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post frankthearm  
                              Started by samish18, Yesterday, 08:57 AM
                              11 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by yertle, Today, 08:38 AM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by love2code2trade, Yesterday, 01:45 PM
                              3 responses
                              22 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Working...
                              X