When deleting in cycle objects
int total_objects = ObjectsTotal(chartid);
for(int o=0; o<total_objects; o++){
string name = ObjectName(chartid, o);
if (is_numeric(StringSubstr(name, 0, 1))){
ObjectDelete(chartid, name);
}
}
not all objects are deleted, for example in the object list table is more than 100 objects, and I trying to delete 50 objects by its name, its first symbols must be numeric. After I run the code, only ~30 objects are deleted, after I rerun code again, 20 objects also deleted.
So I decide that ObjectDelete has a core bug.
Try this way
int total_objects = ObjectsTotal(chartid); for(int o=total_objects-1; o>=0; o--){ string name = ObjectName(chartid, o); if (is_numeric(StringSubstr(name, 0, 1))){ ObjectDelete(chartid, name); } }
Try this way
Wahoo has given you exactly the code you want. The reason is you have fallen into a trap which all programmers fall into (usually once)! When deleting objects it is advisable to delete from the last back to the first, not the first through to the last. If you have 100 objects indexed 0 to 99 and delete the first (the zero numbered element) you will commonly be left with 99 objects now indexed 0 to 98 - and as your code is now about to delete number 1 it will never get back to delete the new number 0. As well as this when your code gets half-way through there will be no objects left numbered 51 through to 100 so you're likely to get a series of overrun type errors as well!
John
Wahoo has given you exactly the code you want. The reason is you have fallen into a trap which all programmers fall into (usually once)! When deleting objects it is advisable to delete from the last back to the first, not the first through to the last. If you have 100 objects indexed 0 to 99 and delete the first (the zero numbered element) you will commonly be left with 99 objects now indexed 0 to 98 - and as your code is now about to delete number 1 it will never get back to delete the new number 0. As well as this when your code gets half-way through there will be no objects left numbered 51 through to 100 so you're likely to get a series of overrun type errors as well!
John

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
When deleting in cycle objects
int total_objects = ObjectsTotal(chartid);
for(int o=0; o<total_objects; o++){
string name = ObjectName(chartid, o);
if (is_numeric(StringSubstr(name, 0, 1))){
ObjectDelete(chartid, name);
}
}
not all objects are deleted, for example in the object list table is more than 100 objects, and I trying to delete 50 objects by its name, its first symbols must be numeric. After I run the code, only ~30 objects are deleted, after I rerun code again, 20 objects also deleted.
So I decide that ObjectDelete has a core bug.