Clear Objects on Chart from "x" bars back

 
//----delete objects
// {
//   for(int z=ObjectsTotal()-1; z>20; z--) {
//      ObjectDelete(ObjectName(z));
//   }
//   Comment("");
//   return(0);
//  }
//----delete objects

Hi everyone, I have been searching with no luck for a way to clear a chart from "x" bars back.  So for example any objects that are older than 50 bars get deleted. I am thinking this code could be modified to do that, it clears the whole chart in it's current state.


Would anyone have any ideas on what to change here?


Thanks for any help!


SD

 
Get the time of the object. get the shift from the time. test.
 
WHRoeder:
Get the time of the object. get the shift from the time. test.
WhRoeder I get that your trying to teach me to fish (appreciate that).  I am not quite following yet.  Are you referring to below?  Would you mind elaborating a bit more to get me off an running?



iBarShift

Search for a bar by its time. The function returns the index of the bar which covers the specified time.

int  iBarShift(
   string           symbol,          // symbol
   int              timeframe,       // timeframe
   datetime         time,            // time
   bool             exact=false      // mode


ObjectGetTimeByValue

The function returns the time value for the specified price value of the specified object.

datetime  ObjectGetTimeByValue(
   string   object_name,   // object name
   double   value,         // price
   int      line_id=0      // line identifier
   );



 
  1. ObjectGetTimeByValue - MQL4 Documentation is used (on all the object types listed) because they have multiple times (Trendline start/end.) and you need a time between them.
  2. If you just need the start time/end time why would you need that?
Reason: