Hello guys!
Today I found out why so simple code, as it always seemed to me, never works as designed
bool doRemoveOldObjects()
{
string name;
int mObjTotal;
int j;
mObjTotal = ObjectsTotal();
for(int i = 0;i < mObjTotal;i++)
{
name=ObjectName(i);
if ( not isObject2Leave( name ) )
{
ObjectDelete(name);
}
}
}
this procedure I used, is designed to remove all but some objets from the chart. And it never worked as I thought it must. It actually deleted only subset of those objects, so I run it 2 or 3 times to delete all I wanted.
Several months passed before I return to this code in another script, and now I realize where the logic flaws. My guess is that when an object is being deleted from a chart, MT4 resets other's indexes, so by taking ObjectName(i) one actually gets different object rather than if the whole set of objects would have left unchanged.
So, I tried another approach. At first I find out the names of objects I want to delete, put them into Array and afterwards run ObjectDelete against that Array. That works!
May be someone will find this info useful. That could save time.
Thank you!
Today I found out why so simple code, as it always seemed to me, never works as designed
bool doRemoveOldObjects()
{
string name;
int mObjTotal;
int j;
mObjTotal = ObjectsTotal();
for(int i = 0;i < mObjTotal;i++)
{
name=ObjectName(i);
if ( not isObject2Leave( name ) )
{
ObjectDelete(name);
}
}
}
this procedure I used, is designed to remove all but some objets from the chart. And it never worked as I thought it must. It actually deleted only subset of those objects, so I run it 2 or 3 times to delete all I wanted.
Several months passed before I return to this code in another script, and now I realize where the logic flaws. My guess is that when an object is being deleted from a chart, MT4 resets other's indexes, so by taking ObjectName(i) one actually gets different object rather than if the whole set of objects would have left unchanged.
So, I tried another approach. At first I find out the names of objects I want to delete, put them into Array and afterwards run ObjectDelete against that Array. That works!
May be someone will find this info useful. That could save time.
Thank you!