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 aa731, Today, 02:54 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post aa731
                  by aa731
                   
                  Started by thanajo, 05-04-2021, 02:11 AM
                  3 responses
                  470 views
                  0 likes
                  Last Post tradingnasdaqprueba  
                  Started by Christopher_R, Today, 12:29 AM
                  0 responses
                  10 views
                  0 likes
                  Last Post Christopher_R  
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  166 responses
                  2,237 views
                  0 likes
                  Last Post sidlercom80  
                  Started by thread, Yesterday, 11:58 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post thread
                  by thread
                   
                  Working...
                  X