Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cast Text from DrawObjects

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

    Cast Text from DrawObjects

    From the Help Guide: Lets say this is in Indi_001:
    Text myText;
    protected override void OnBarUpdate()
    {
    if(CurrentBar==50) myText=Draw.Text(this,"tag","test",0,High[0]);
    if(myText !=null ) Print(myText.Anchor.DrawnOnBar);// drawn on bar 50
    }
    .. then in Indi_002 I want to retrieve that text. I can get it with a foreach loop looking at all the tags for "tag"
    But I know the tag, so I try to read it directly with DrawObjects["tag"] and I can get it semi OK
    It shows me the Tag.
    But when I try to show DisplayName I get all sorts of errors for bad cast etc. Ive tried all sorts of combinations to get this, and even one that looks right and compiles. But it gives a run-time error of no instance assigned etc.
    I need to see DrawObjects["tag"].DisplayName and then Time.
    "missing a using or cast.??.."
    Last edited by kenz987; 04-11-2025, 11:30 AM.

    #2
    Hello kenz987,

    Thank you for your post.

    If you want to get the actual text you would need to use DisplayText, not DisplayName. Please see this forum post that discusses:



    Please let us know if you have any further questions.

    Comment


      #3
      Thanks Gaby, But thats no help. I want to avoid a loop. My Count gets very large. I have the tag, how do I get the data with DrawObjects["tag"] . . ??

      Comment


        #4
        The same concept still applies, you would access it from the DrawObjects collection via the tag.



        Code:
        if (DrawObjects["someTag"] != null && DrawObjects["someTag"] is DrawingTools.Text)
        {
        DrawingTools.Text myDrawText = DrawObjects["someTag"] as DrawingTools.Text;
        Print(myDrawText.DisplayText);
        }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        65 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        149 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        162 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        99 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        286 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X