How to get value of an object in a chart

To add comments, please log in or register
TradeForexFx
64
TradeForexFx  

Hi all,


I need help as follows:

1) There are numerous Objects in the chart, I am interested to get value of the object on a specific bar of the chart. 

2) Object with the names, as an example, "XYZ04", "XYZ110", "XYZ005"  appear on the chart, therefore I know the prefix, but I do not know the suffix which could be 112, 198, 110,13, etc. 


The methodology could be:

1) Determine all the objects with suffix "XYZ" in the chart.

2) Check which one is on the specific bar and get its value.


I went through various ObjectGet, ObjectFind functions but could not put them together to get my desired result.


Appreciate help to resolve the problem



Thanks

Mohamad Zulhairi Baba
16412
Mohamad Zulhairi Baba  
TradeForexFx:

Hi all,


I need help as follows:

1) There are numerous Objects in the chart, I am interested to get value of the object on a specific bar of the chart. 

2) Object with the names, as an example, "XYZ04", "XYZ110", "XYZ005"  appear on the chart, therefore I know the prefix, but I do not know the suffix which could be 112, 198, 110,13, etc. 


The methodology could be:

1) Determine all the objects with suffix "XYZ" in the chart.

2) Check which one is on the specific bar and get its value.


I went through various ObjectGet, ObjectFind functions but could not put them together to get my desired result.


Appreciate help to resolve the problem



Thanks

StringSubstr

Mohamed Nabil Zaki
12633
Mohamed Nabil Zaki  
TradeForexFx:

Hi all,


I need help as follows:

1) There are numerous Objects in the chart, I am interested to get value of the object on a specific bar of the chart. 

2) Object with the names, as an example, "XYZ04", "XYZ110", "XYZ005"  appear on the chart, therefore I know the prefix, but I do not know the suffix which could be 112, 198, 110,13, etc. 


The methodology could be:

1) Determine all the objects with suffix "XYZ" in the chart.

2) Check which one is on the specific bar and get its value.


I went through various ObjectGet, ObjectFind functions but could not put them together to get my desired result.


Appreciate help to resolve the problem



Thanks


Hi 
You can loop through all objects on the chart 
Objectstotals() then using StringFind(suffix) function  and determine the desired object type then you can get the value of each object using many ways . To know the proper way you have to tell the type of abjects . Generally you can get the value of object using obgectgey value by time functuin
Anthony Garot
3264
Anthony Garot  
TradeForexFx: 


The methodology could be:

1) Determine all the objects with suffix "XYZ" in the chart.

2) Check which one is on the specific bar and get its value.

Have not tested this:

        string needle = "XYZ";
        int length = StringLen(needle);
        string bar = "110";

        int numObjects = ObjectsTotal(NULL,NULL,-1);
        for(int i = numObjects; i >= 0 ; i--)
        {
                if ( StringSubstr(ObjectName(NULL,i,NULL,-1), 0, length) == needle )
                {
                        if ( StringSubstr(ObjectName(NULL,i,NULL,-1), length) == bar )
                        {
                                Print("found it");
                        }
                }
        }
TradeForexFx
64
TradeForexFx  
Mohamed Nabil:

Hi 
You can loop through all objects on the chart 
Objectstotals() then using StringFind(suffix) function  and determine the desired object type then you can get the value of each object using many ways . To know the proper way you have to tell the type of abjects . Generally you can get the value of object using obgectgey value by time functuin

Thanks for the quick reply.

These are trendlines. I reviewed other forum post, tried to play around with those codes. They also revolved around Objectstotals(),StringFind(), ObjectGetvalueByShift()... As I am sort of a "copy paste" coder, could not put things together. My requirement is probably well understood by you, if you could put together the codes it will be very much appreciated.


Thanks

TradeForexFx
64
TradeForexFx  
Anthony Garot:

Have not tested this:

Thanks Garrot,


Will check your suggested codes. It seems that you have considered the suffix "110" as known. Is that so? The suffix for my requirement is not known. The prefix is known.


After finding all the possible objects, I need to find the one at the specific bar (0,1,2 shift).

Anthony Garot
3264
Anthony Garot  
TradeForexFx:

Thanks Garrot,


Will check your suggested codes. It seems that you have considered the suffix "110" as known. Is that so? The suffix for my requirement is not known. The prefix is known.

It's in your example. Obviously you would change that as circumstance requires.
Mohamed Nabil Zaki
12633
Mohamed Nabil Zaki  
TradeForexFx:

Thanks for the quick reply.

These are trendlines. I reviewed other forum post, tried to play around with those codes. They also revolved around Objectstotals(),StringFind(), ObjectGetvalueByShift()... As I am sort of a "copy paste" coder, could not put things together. My requirement is probably well understood by you, if you could put together the codes it will be very much appreciated.


Thanks

try this code it's function that returnes the trend line value at specific bar . the function takes 2 parameters , 1st is the prefix as string , 2nd the suffux as integer which is the index I assume

double TrendVal(int suffix , string prefix)
 {
  double val=-1 ;
  string name=prefix+(string)suffix ;
  
  for(int i=0;i<ObjectsTotal();i++)
    {
     string objectname=ObjectName(i) ;
     if(StringFind(name,prefix,0)<0 || ObjectType(objectname)!=OBJ_TREND)continue ;
     if(name==objectname)
      {
       val=ObjectGetValueByShift(name,suffix) ;
       break ;
      }
     
     
    }
   return(val);
 }
TradeForexFx
64
TradeForexFx  
Mohamed Nabil:

try this code it's function that returnes the trend line value at specific bar . the function takes 2 parameters , 1st is the prefix as string , 2nd the suffux as integer which is the index I assume

Compilation error


'TrendVal' - function can be declared only in the global scope

TradeForexFx
64
TradeForexFx  
TradeForexFx:

Compilation error


'TrendVal' - function can be declared only in the global scope

I will put my requirement in a different way. As mentioned above I am a sort of "copy paste" coder and putting together a suggested method will be difficult for me. Hopefully someone can provide me a somewhat complete code to achieve the following :

I want to get the value of a trendline at a specific bar on the chart. Full name of the object is not known, only the prefix is known. The suffix is not known. The chart may have more than one object with the same known prefix and different suffix(es).


Thanks for any help

William Roeder
20210
William Roeder  
TradeForexFx: 'TrendVal' - function can be declared only in the global scope

You pasted the code inside another function. Move it outside.

12
To add comments, please log in or register