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
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 )
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.
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).
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 ;
string objectname=ObjectName(i) ;
if(StringFind(name,prefix,0)<0 || ObjectType(objectname)!=OBJ_TREND)continue ;
'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
You pasted the code inside another function. Move it outside.