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

Code to Read "Draw Text"

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

    Code to Read "Draw Text"

    Hello,

    Is it possible to read the value of text written to a chart using the DrawText method?

    For instance, say I have an indicator that prints a text string to a chart. Is there a convenient way to programatically return the text to a string variable?

    Thank you.

    Isaac

    #2
    Hello Issac,

    Yes, it would be possible to print the text of a text box.

    Here is some code to point you in the right direction.

    Code:
    foreach(IDrawObject draw in DrawObjects)
    {
    if (draw.DrawType == DrawType.Text)
    {
    IText text;
    text = (IText) draw;
    if (text == null)
    return;
    Print(text.Text);
    }
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Excellent. Thank you for the prompt reply.

      Comment


        #4
        But for this to work, would the DrawObject have to be created internally by my code? Or it this approach able to read a DrawObject that is created inside an indicator that runs inside my strategy?

        Comment


          #5
          Hello ivb73077,

          This code will detect all objects manual or not.

          Objects that are not made by this instance of the strategy, will be read-only.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Perfect. Thanks again.

            Read-only is fine as I just need to pull the string value...I will not be modifying it.

            Comment


              #7
              Follow-up question: the suggestion provided requires iteration over all the DrawObjects.

              Is there a way to assess if a particular bar has a DrawObject associated with it and then simply read the properties of that object.

              For example, if my strategy runs on 5-minute bars and I want to know if there is a DrawObject on the prior bar, can I get this without needing to iterate over all DrawObjects? Is there some property that tells me if the bar has a DrawObject?

              I want to minimize the looping done in the code if at all possible.

              Thank you.

              Isaac

              Comment


                #8
                Hello Isaac,

                The suggested code loops through all objects so that ones that are manually drawn can be found. If the objects are set by code, the DrawText() method returns an IText object that you can set to a variable handle and do whatever you like with (you could also make a list to contain these.)

                in #region Variables:
                private IText myText;

                wherever you are drawing text:
                myText = DrawText("textBox", "some text here", 0, Low[0] - 4 * TickSize, Color.Black);
                Print(myText.Text);

                http://www.ninjatrader.com/support/h.../nt7/itext.htm
                Last edited by NinjaTrader_ChelseaB; 06-01-2015, 08:11 AM.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you .

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Waxavi, Today, 02:10 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post Waxavi
                  by Waxavi
                   
                  Started by TradeForge, Today, 02:09 AM
                  0 responses
                  11 views
                  0 likes
                  Last Post TradeForge  
                  Started by Waxavi, Today, 02:00 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post Waxavi
                  by Waxavi
                   
                  Started by elirion, Today, 01:36 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post elirion
                  by elirion
                   
                  Started by gentlebenthebear, Today, 01:30 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post gentlebenthebear  
                  Working...
                  X