• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Retrieving Drawing Object Information AND buttons

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

    Retrieving Drawing Object Information AND buttons

    I noticed when Drawing in order and hit properties on Lines fibs etc it shows
    the TAG name 0, 1, 2 as well as the data.

    How do you access a Drawing objects information and find out the drawing type.
    Once I know the type how would I access the Data of that drawing object?


    Example: I draw a ray, then I draw a fib, then I draw a Vertical Line I know the Tags would be

    TAG 0 == ray
    TAG 1 == fib
    TAG 2 == Vertical line

    Can you also get the count of the object drawn?

    For example the Tag Numbers will always increase even if you delete them.

    __________________________________________________ ___________

    Second question on buttons

    My button methodology works but I have some parameters for color coding and sizes won't update unless I press F5 (reload ninja script)
    Last edited by ballboy11; 11-10-2017, 07:52 AM.

    #2
    Hello ballboy11,

    Thanks for opening the thread.

    There is a DrawObjects collection of IDrawObject's that you can loop through to get information about the Drawing Objects drawn on a chart. The documentation page on DrawObjects contains sample code on how you you can loop through the collection, find a DrawObject that is a particular type, and then change its color and print its anchors.

    Code:
    foreach (IDrawObject draw in DrawObjects)
     {
             // Finds line objects that are attached globally to all charts of the same instrument
             if (draw.Tag.StartsWith("@") && draw is ILine)
             {
                     ILine globalLine = (ILine) draw;
     
                     // Changes the line color and prints its starting and end points
                     globalLine.Pen.Color = Color.Black;
                     Print("Start: " + globalLine.StartBarsAgo + " End: " + globalLine.EndBarsAgo);
             }
     
             // Finds non-global line objects
             else if (draw is ILine)
             {
                     ILine drawnLine = (ILine) draw;
     
                     // Determines if this is a manually drawn or script generated line
                     Print("Line Object: " + draw.Tag + " Manually Drawn: " + draw.UserDrawn);
             }
     }
    You can get the count of how many draw objects are in the collection, but you cannot get the index of a draw object within that collection.

    I have included links to our openly available documentation on DrawObjects and IDrawObject.

    DrawObjects - https://ninjatrader.com/support/help...rawobjects.htm

    IDrawObject - https://ninjatrader.com/support/help...drawobject.htm

    As for your question regarding buttons, are you changing colors by looping through a collection or are you changing the color property that would then be used to draw new instances? For example, looping through BarColors[] and setting them all to a certain color when changing BarColor will change the color used for subsequent bars.

    I helped another client with a similar button for NinjaTrader 8. The related documentation for NinjaTrader 7 would need to be referenced but the concepts should be similar.

    Link: https://ninjatrader.com/support/foru...d.php?t=105491

    If this information does not resolve your inquiry, could you provide more information on what exactly you are changing and how within your button?
    JimNinjaTrader Customer Service

    Comment


      #3
      Ok I went through the loop and now how do I access the data for the DrawObject?


      Print("Line Object: " + draw.Tag + " Manually Drawn: " + draw.UserDrawn + " draw type " + draw.DrawType);
      if(DrawObjects["0"].DrawType == DrawType.Ray)
      {
      Print("true");
      // IRay ray = DrawObjects["0"];

      I want to get the Ray Data
      }

      Comment


        #4
        OK i figured how to get the information on a string, but how would I parse this out?

        Name='Ray' Time='2017-11-10 10:23:00 AM', StartBar='21410' StartY='6300.84' EndTime='2017-11-10 10:40:00 AM' EndBar='21427' EndY='6305.69'

        Comment


          #5
          Hello ballboy11,

          I would instead suggest to access the properties of the IRay rather than to print a string and extract the information.

          In the example code above, an ILine object is created and "draw" is casted as an ILine and assigned to "globalline." "globalline" can be then be accessed as an ILine.

          Code:
          ILine globalLine = (ILine) draw; // Change to IRay
          You can do the same thing for an IRay and then to access the properties of the IRay object. An IRay will have its own properties as well as properties inherited from IDrawingObject.

          I've included a link to the IRay documentation to reference the properties and methods available within.

          IRay - https://ninjatrader.com/support/helpGuides/nt7/iray.htm

          If you have any additional questions, please don't hesitate to write back.
          JimNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by pjsmith, Today, 02:56 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by bubblegum, Today, 01:13 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Started by TraderYoda, Today, 03:33 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_EricB  
          Started by fredfred, Today, 03:41 AM
          5 responses
          18 views
          0 likes
          Last Post NinjaTrader_ChristopherS  
          Started by ntbone, Yesterday, 08:10 PM
          0 responses
          15 views
          0 likes
          Last Post ntbone
          by ntbone
           
          Working...
          X