Finding an ObjectType on multiple charts without knowing object name

 

In MT4, is it possible to read through all open charts and count all the HLINE and TREND objects of a specific color?  I have the following code and know that the statements after the "for" loop will not work because the ObjectName function does not have a ChartID parameter.  I tried looking for something else that might work (e.g. ObjectGetString) but haven't found anything.

 

int OnCalculate (const int rates_total,      // size of input time series 
                 const int prev_calculated,  // bars handled in previous call 
                 const datetime& time[],     // Time 
                 const double& open[],       // Open 
                 const double& high[],       // High 
                 const double& low[],        // Low 
                 const double& close[],      // Close 
                 const long& tick_volume[],  // Tick Volume 
                 const long& volume[],       // Real Volume 
                 const int& spread[]) {      // Spread 
   uchar  Lines[2];
   ulong  ID;
   ushort x;
   ArrayInitialize(Lines,0);
   for(ID = ChartFirst(); ID != -1; ID = ChartNext(ID)) {
      for (x = 0; x < ObjectsTotal(ID,0,-1); x++) {
         if ((ObjectType(ObjectName(x)) == OBJ_HLINE) || (ObjectType(ObjectName(x)) == OBJ_TREND)) {
            if (ObjectGetInteger(ID,ObjectName(x),OBJPROP_COLOR) == clrCyan)
               Lines[0]++;
            if (ObjectGetInteger(ID,ObjectName(x),OBJPROP_COLOR) == clrMaroon)
               Lines[1]++;
         }
      }
   }
   Comment(Lines[0]+"   "+Lines[1]);
   return(rates_total);
}
 

Use ObjectName with ChartID, it will work.




 
eddie:

Use ObjectName with ChartID, it will work.




I already tried replacing ObjectName(x) with ObjectName(ID,x) in the three lines that used it, it did not work.  Well, it retrieved the object name, but the ObjectType function did not work, it returned -1 for all objects on charts where indicator was not loaded.  It returned correct values for the chart the indicator was loaded on.  Code does not compile when you try to put ChartID in ObjectType parameter list.
 

If you got the name you call ObjectGetInteger to get the Type.

 
eddie:

If you got the name you call ObjectGetInteger to get the Type.

OK, thanks.  The following works:

 

if ((ObjectGetInteger(ID,ObjectName(ID,x),OBJPROP_TYPE) == OBJ_HLINE) || (ObjectGetInteger(ID,ObjectName(ID,x),OBJPROP_TYPE) == OBJ_TREND)) {

 

The MQL4 Reference help file needs to be updated to show that you can use ID with ObjectName. 

 
Daniel Lewis:

OK, thanks.  The following works:

 

 

The MQL4 Reference help file needs to be updated to show that you can use ID with ObjectName. 

thanks for sharing 

hope that service desk report the same to update help file/s for MQL4

Reason: