//+------------------------------------------------------------------+
//|                                          ObjectsDeleteCustom.mq4 |
//|                                          Copyright 2022 mql5.com |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022 mql5.com"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

input string                   ObjectString1             ="";
input string                   ObjectString2             ="";
input string                   ObjectString3             ="";
input string                   ObjectString4             ="";
input string                   ObjectString5             ="";
input string                   ObjectString6             ="";
input string                   ObjectString7             ="";
input string                   ObjectString8             ="";
input string                   ObjectString9             ="";

string ObjectString = "ObjectString";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---    
                 objectsDelete(ObjectString1);
                 objectsDelete(ObjectString2);
                 objectsDelete(ObjectString3);
                 objectsDelete(ObjectString4);
                 objectsDelete(ObjectString5);
                 objectsDelete(ObjectString6);
                 objectsDelete(ObjectString7);
                 objectsDelete(ObjectString8);
                 objectsDelete(ObjectString9);

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
void objectsDelete(string name)
{
   int objTotal = ObjectsTotal();
   for(int i=objTotal-1; i>=0; i--)  
  {
      string objName = ObjectName(i);
      if(StringFind(objName,name,0) == 0)
       ObjectDelete(0,objName);
   }
}
//+------------------------------------------------------------------+
