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 text from text object

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

    access text from text object

    Hi,

    I draw some text on the chart by using DrawText:

    DrawText("TextShort"+CurrentBar, true, BearSBText, 0, High[0]+5*TickSize, 0, Color.Red, new Font ("Arial", Font), StringAlignment.Center, Color.Empty, Color.Empty, 0);

    How can I access the text string (BearSBText) from such an object some bars later?

    Cheers

    Thomas

    #2
    Hello Thomas,

    Thank you for your post.

    May I ask for clarification on your request?

    Do you wish to access the text that is drawn on the chart? Or are you attempting to DrawText once more at a later time with the same string as used earlier?

    The following Print sample shows how you can access the variable: Print(BearSBText);

    I look forward to assisting you further.

    Comment


      #3
      Hi Patrick,

      I'd like to access (two bars after the text was drawn) BearSBText, do some comparison and either delete the object or keep it. Like this:

      if (FirstTickOfBar)
      {
      previousBar = CurrentBar - 2;
      if (High[1]<=High[2] && - here goes some other condition that compares
      BearSBText to something -)
      RemoveDrawObject("TextLong"+previousBar);
      }

      Comment


        #4
        Hi td_910,

        If you want to work with the number of bars since a condition, there is MRO() and LRO() dedicated for this. Use your High[1]<=High[2] condition in these and can then reference the bar the condition occurred on. Example usage is available at link below:


        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          DrawText("TextLong"+CurrentBar, true, BullSBText, 0, Low[0]-5*TickSize, 0, Color.Green, new Font ("Arial", Font), StringAlignment.Center, Color.Empty, Color.Empty, 0);
          DrawText("TextShort"+CurrentBar, true, BearSBText, 0, High[0]+5*TickSize, 0, Color.Red, new Font ("Arial", Font), StringAlignment.Center, Color.Empty, Color.Empty, 0);

          This is how I draw my text objects.

          In the attached example chart the first (green) "I" signal (Long) is deleted because it does not trigger on the next bar. The "DBT" signal (Short) should be kept regardless if it triggers on the next bar or not.

          That's why I'm checking on the first tick of a bar whether High[1]<=High[2] and would like to add a condition that keeps the object with the "DBT" text.


          E.g. what is the syntax to access the text (displayed in the General tab of object properties) of a text object with the tag "TextLong13425"?
          Attached Files
          Last edited by td_910; 04-16-2012, 07:26 AM.

          Comment


            #6
            Hello td_910,

            Thank you for your response.

            You will first have to setup the DrawText with IText, which will allow any of the properties to be accessed, for example if you wanted to access the text from a DrawText object:

            Code:
            // Draws a text object
            IText text = DrawText("tag1", "Text to draw", 10, 1000, Color.Black);
            
            // Print the text drawn on the chart
            Print(text.Text);
            For information on IText please visit the following link: http://www.ninjatrader.com/support/h.../nt7/itext.htm
            Please let me know if I may be of further assistance.

            Comment


              #7
              changed my code to:
              IText TLong = DrawText("TextLong"+CurrentBar, true, BullSBText, 0, Low[0]-6*TickSize, 0, Color.Green, new Font ("Arial", Font), StringAlignment.Center, Color.Empty, Color.Empty, 0);

              Print(TLong.Text);
              works and prints the Text of the current bar (bar0) but how do I reference the Text of two bars ago?

              tried this
              TLong[2].Text

              but no success, I get compiler error CS0021

              The second problem I have is: I'd like to check for the condition at the beginning of OnBarUpdate but create the objects much further down in the code.
              and get: CS0103 The name 'identifier' does not exist in the current context
              Last edited by td_910; 04-17-2012, 03:03 PM.

              Comment


                #8
                Originally posted by td_910 View Post
                changed my code to:
                IText TLong = DrawText("TextLong"+CurrentBar, true, BullSBText, 0, Low[0]-6*TickSize, 0, Color.Green, new Font ("Arial", Font), StringAlignment.Center, Color.Empty, Color.Empty, 0);

                Print(TLong.Text);
                works and prints the Text of the current bar (bar0) but how do I reference the Text of two bars ago?

                tried this
                TLong[2].Text

                but no success, I get compiler error CS0021

                The second problem I have is: I'd like to check for the condition at the beginning of OnBarUpdate but create the objects much further down in the code.
                and get: CS0103 The name 'identifier' does not exist in the current context
                Your IText tag is "TextLong"+CurrentBar, as you have defined it. Therefore, the tag 2 bars ago is "TextLong"+(CurrentBar - 2).ToString()

                Comment


                  #9
                  koganam, many thanks for that
                  this prints the tag, but how do I access the text (that is printed on the chart) of that object

                  I was confused by the provided example (programmed MQL4 in my earlier life :-))

                  // Draws a text object
                  IText text = DrawText("tag1", "Text to draw", 10, 1000, Color.Black);
                  // Print the text drawn on the chart
                  Print(text.Text);


                  it seems to access the text of the object without referencing the tag!?
                  Last edited by td_910; 04-18-2012, 02:00 AM.

                  Comment


                    #10
                    Hello td_910,

                    Thank you for your response.

                    You are correct as Print(text.Text); is printing the text of the DrawText object without referencing the tag, however it has been assigned the identifier "text" which is being referenced.

                    However, as you are dynamically updating the text in your code (BearSBText) and placing the DrawText object at several points we recommend using a StringSeries class to store these string values (much like a DataSeries does with data). This will allow you to reference the text at several places in your code, such as Text[2] for referencing 2 bars ago.

                    Information on StringSeries class can be found at the following link: http://www.ninjatrader.com/support/h...ries_class.htm

                    For a reference on using a DataSeries object to store information please visit the following link (this example will use BoolSeries class instead of StringSeries class): http://www.ninjatrader.com/support/f...ead.php?t=7299

                    Please let me know if I may be of further assistance.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by mmenigma, Today, 02:22 PM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by frankthearm, Today, 09:08 AM
                    9 responses
                    35 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by NRITV, Today, 01:15 PM
                    2 responses
                    9 views
                    0 likes
                    Last Post NRITV
                    by NRITV
                     
                    Started by maybeimnotrader, Yesterday, 05:46 PM
                    5 responses
                    26 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by quantismo, Yesterday, 05:13 PM
                    2 responses
                    21 views
                    0 likes
                    Last Post quantismo  
                    Working...
                    X