How to read TEXT from the object label ?

 

I want to pick up some text from the Object.

But Object name has some time stamp, so I just want to pick up if the label contains some letters.

For example,

Object name is "DE1200"

sometimes it is "DE1233"

So how can I read text from the object? It contains "DE", so my code is below.

     for(int k=0;k<ObjectsTotal(0,0, OBJ_TEXT);k++) 
      { 
       string text = ObjectGetString(0,"DE***",OBJPROP_TEXT);
      }

Do you have a good solution ?

 
     for(int k=0;k<ObjectsTotal(0,0, OBJ_TEXT);k++) 
      { 
       string ob_name = ObjectName(k);
       if(StringFind(ob_name,"DE")!=0) continue;
       string text = ObjectGetString(0,ob_name,OBJPROP_TEXT);
      }

use this code

 
Trinh Dat #:

use this code

Wonder! Wonder! Wonderful!

 
Trinh Dat #:

use this code

Hi,Trinh

I am still in trouble.

Please  see below.

I want to read below Text which is "StopLoss 1.26168" from the object on the chart.

If text name contains "1651719720", then pick up the Text label from the object.


This is my code. But something wrong with it. It does not work properly. Can you point out why?

 string text;
 string ob_name;

  for(int k=0;k<ObjectsTotal(0,0, OBJ_TEXT);k++) 
      { 
   
       ob_name = ObjectName(k);
       if(StringFind(ob_name,"1651719720")!=0)continue;
      }
        text = ObjectGetString(0,ob_name,OBJPROP_TEXT);
       Print(text);

}
 
#define MAIN_WINDOW  0
 for(int k=0;k<ObjectsTotal(0,MAIN_WINDOW, OBJ_TEXT);k++) 
      { 
       ob_name = ObjectName(k);
You are getting the count of only text objects, but reading all objects.
 
William Roeder #:
You are getting the count of only text objects, but reading all objects.

Hi, William

Thank you for your advice.

I thought the object was text because it shows "Object Text" like below picture.

But when I changed like below, it worked! 

The object was not text ?

 #define MAIN_WINDOW  0
 for(int k=0;k<ObjectsTotal(0,MAIN_WINDOW);k++)
 
Cromo #: I thought the object was text because it shows "Object Text" like below picture.

Irrelevant.

#define MAIN_WINDOW  0
 for(int k=0;k<ObjectsTotal(0,MAIN_WINDOW, OBJ_TEXT);k++) 
      { 
       ob_name = ObjectName(k);
  1. Assume you have only some other objects (count ≥ 2) and then two text objects in that order.
  2. You ask for how many text objects; answer two.
  3. You loop from [0 … 1] (over two). How many text objects will you find?