Finding an ObjectType on multiple charts without knowing object name

Back to topics list To post a new topic, please log in or register
avatar
26
dlewisfl 2016.08.08 23:30
 

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);
}

 

avatar
108
eddie 2016.08.09 00:12 #
 

Use ObjectName with ChartID, it will work.




avatar
26
dlewisfl 2016.08.09 04:16 #
 
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.
avatar
108
eddie 2016.08.09 10:46 #
 

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

avatar
26
dlewisfl 2016.08.09 13:22 #
 
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. 

Back to topics list  

To add comments, please log in or register