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

access property of draw object

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

    access property of draw object

    Hi,

    How would that code segment look in NT8?

    ILine myline = (ILine)DrawObjects["AIL_Line"+(CurrentBar-2)];
    if (myline != null)
    {
    myline.Pen.DashStyle = DashStyle.Dash;
    myline.Pen.Width = 2;
    {
    The line is drawn in a local if statement.

    Thanks

    #2
    Hello td_910,

    Thanks for the post.

    The ILine interface was replaced with the Line object.

    The DrawObjects collection is the same.

    Pens have been replaced with the Stroke class, that takes a WPF Brush in its constructor.

    Changing these parts of the code should work for you.

    Please let me know if I can assist further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks for that!

      Is it possible to instantiate a Line object later, only knowing it's tag?
      e.g. to query a property...

      Comment


        #4
        Hello td_910,

        Thanks for the reply

        I'm not sure what you mean, could you clarify further?
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          e.g. if I instantiate a text object like that within a local if clause

          Text myText_Bull = null;

          if (High[1]<High[0])
          {
          myText_Bull = Draw.Text(this, "BSP_Bull"+(CurrentBar), true, "A", 0, High[0], offset, decreasing_Symbol_Color, myFont, TextAlignment.Center, Brushes.Transparent, ...
          }
          else
          {
          RemoveDrawObject("BSP_Bull"+(Curren tBar));
          myText_Bull = null;
          }

          How do I access the text properties for e.g. CurrentBar-1 at some later stage?

          Thanks




          Last edited by td_910; 10-12-2018, 02:24 PM.

          Comment


            #6
            Hello td_910,

            Thanks for the reply.

            You need to use the DrawObjects collection to access drawing objects made in the past. From what I can see it looks like the code should work.

            Please let me know if I can assist further.

            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ChrisL View Post
              Hello td_910,

              Thanks for the reply.

              You need to use the DrawObjects collection to access drawing objects made in the past. From what I can see it looks like the code should work.

              Please let me know if I can assist further.
              yes right, does this work?

              if(DrawObjects["BSP_Bull"+(CurrentBar-1)] != null)
              {
              if (myText_Bull.TextBrush == Brushes.LimeGreen)
              do something
              }

              Comment


                #8
                Hello td_910,

                Thanks for the reply.

                Yes, the index of the collection is just a collection of tags used as keys in a key/value pair. As long as you have an object with that tag, NinjaTrader will be able to find it.

                Please let me know if I can assist further.
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Text myText_Bull = null;

                  if (High[1]<High[0])
                  {
                  myText_Bull = Draw.Text(this, "BSP_Bull"+(CurrentBar), true, "A", 0, High[0], offset, decreasing_Symbol_Color, myFont, TextAlignment.Center, Brushes.Transparent, ...
                  }
                  else
                  {
                  RemoveDrawObject("BSP_Bull"+(Curren tBar));
                  }

                  Does the myText_Bull only contain the properties of the last instantiated text object with the tag "BSP_Bull12345"? Or also all prior ones like "BSP_Bull12344" "BSP_Bull12343" ...

                  and how do I reference them using myText_Bull?

                  Comment


                    #10
                    Hello td_910,

                    Yes, the myText_Bull variable can only hold a single object.

                    If you want to hold multiple objects, use a list with the type Text (List<Text>) or similar type of collection.

                    Below is a public link to a 3rd party educational site on List.
                    Create a new List, add elements to it, and loop over its elements with for and foreach.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      this sounds pretty complicated to me, I hope, that it doesn't get that complicated to achieve that

                      This was my code in NT7

                      DrawLine("AIL_Line"+(CurrentBar-2).....

                      ILine myline = (ILine)DrawObjects["AIL_Line"+(CurrentBar-2)];
                      if (myline != null)
                      {
                      myline.Pen.DashStyle = DashStyle.Dash;
                      myline.Pen.Width = 2;
                      }

                      I don't want to hold ALL Line draw objects in an additional list, because they're in the DrawObjects collection anyway
                      I just want to assign ONE line, as needed, to the myline variable to check for properties of that line object
                      This can't be so much different on NT8 compared to NT7!?

                      Comment


                        #12
                        Hello td_910,

                        Thanks for the reply.

                        This would be the direct conversion of the NT7 code you posted.

                        Code:
                        Draw.Line(this, "MyLine"+(CurrentBar-2), 5, Close[5], 0, Close[0], Brushes.Red);
                        
                        NinjaTrader.NinjaScript.DrawingTools.Line myLine = (NinjaTrader.NinjaScript.DrawingTools.Line)DrawObjects["MyLine"+(CurrentBar-2)];
                        
                        if(myLine != null)
                        {
                              //Access myLine properties.
                        }
                        There is also an example of how to loop through the DrawObjects array on the DrawObjects help guide page under the header "Looping through the collection to find specific draw objects"

                        Please let me know if I can assist further.
                        Chris L.NinjaTrader Customer Service

                        Comment


                          #13
                          Great, thanks a lot. More or less the same syntax :-)

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by sidlercom80, 10-28-2023, 08:49 AM
                          166 responses
                          2,233 views
                          0 likes
                          Last Post sidlercom80  
                          Started by thread, Yesterday, 11:58 PM
                          0 responses
                          1 view
                          0 likes
                          Last Post thread
                          by thread
                           
                          Started by jclose, Yesterday, 09:37 PM
                          0 responses
                          6 views
                          0 likes
                          Last Post jclose
                          by jclose
                           
                          Started by WeyldFalcon, 08-07-2020, 06:13 AM
                          10 responses
                          1,414 views
                          0 likes
                          Last Post Traderontheroad  
                          Started by firefoxforum12, Yesterday, 08:53 PM
                          0 responses
                          11 views
                          0 likes
                          Last Post firefoxforum12  
                          Working...
                          X