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

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 TraderBCL, Today, 04:38 AM
          2 responses
          16 views
          0 likes
          Last Post TraderBCL  
          Started by martin70, 03-24-2023, 04:58 AM
          14 responses
          106 views
          0 likes
          Last Post martin70  
          Started by Radano, 06-10-2021, 01:40 AM
          19 responses
          609 views
          0 likes
          Last Post Radano
          by Radano
           
          Started by KenneGaray, Today, 03:48 AM
          0 responses
          5 views
          0 likes
          Last Post KenneGaray  
          Started by thanajo, 05-04-2021, 02:11 AM
          4 responses
          471 views
          0 likes
          Last Post tradingnasdaqprueba  
          Working...
          X