Hide an object when the scale of a chart changes

 

I want to hide an object on a chart in Mt5 when the scale of this chart changes to 0 or 1 (the scale can change from 0 to 5).  unfortunately MQL5 does not have a command like   

ObjectSetInteger(0, "name", OBJPROP_TIMEFRAMES, OBJ_PERIOD_H1|OBJ_PERIOD_D1)

for chart_scale.  I found a way to hide and unhide an object in different scales and timeframes.  By using "CHARTEVENT_CHART_CHANGE" we can do it:

void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
{
   if(id== CHARTEVENT_CHART_CHANGE)
   {
      if(ChartGetInteger(0 ,CHART_SCALE, 0) <= 1)
      {
         ObjectSetInteger(0, "name", OBJPROP_TIMEFRAMES, OBJ_NO_PERIODS);
      }
      else
      {
         ObjectSetInteger(0, "name", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M1|OBJ_PERIOD_M5|OBJ_PERIOD_M15);      
      }
   }
}
But when there are 100 objects, this way can not be good. My question is : Is there a way for 100 objects?
 
Jo JomaxBut when there are 100 objects, this way can not be good. My question is : Is there a way for 100 objects?

Why do you think it's “not good,” (whatever that means)?

Go through the object list and change them one by one.

 
William Roeder #:

Why do you think it's “not good,” (whatever that means)?

Go through the object list and change them one by one.

I thought I should copy-paste 100 times the following code and then change the names:

   if(id== CHARTEVENT_CHART_CHANGE)
   {
      if(ChartGetInteger(0 ,CHART_SCALE, 0) <= 1)
      {
         ObjectSetInteger(0, "x", OBJPROP_TIMEFRAMES, OBJ_NO_PERIODS);
         ObjectSetInteger(0, "y", OBJPROP_TIMEFRAMES, OBJ_NO_PERIODS);
         .
         .
         .         
      }
      else
      {
         ObjectSetInteger(0, "x", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M1|OBJ_PERIOD_M5|OBJ_PERIOD_M15);
         ObjectSetInteger(0, "y", OBJPROP_TIMEFRAMES, OBJ_NO_PERIODS);
         .
         .
         .
      }
   }

But I can use the following code:


void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
{
   if(id== CHARTEVENT_CHART_CHANGE)
   {
      if(ChartGetInteger(0 ,CHART_SCALE, 0) <= 1)
      {
         for(int i=0; i< ObjectsTotal(); i++)
         {
            if(ObjectGetInteger(0, ObjectName(0, i, 0, 1), OBJPROP_TYPE, 0) == OBJ_HLINE)
            {
               ObjectSetInteger(0, ObjectName(0, i, 0, 1), OBJPROP_TIMEFRAMES, OBJ_NO_PERIODS);         
            }
         }            
      }
      else
      {
         .
         .
         .
      }
   }
}

Thank you for your idea. I think there is no another way.