Objects disappeared but reappear if I rename them

 

Hi,

It's probably kind of a basic problem. I am coding a table with lot of objects to write different values. I don't know exactly what I changed but suddenly all objects disappeared, switching timeframes etc. didn't help. Then I found out that if I change the object name (add or delete one character for example) the object will be shown again.

The code is over 700 lines long and hence I guess no one would be too happy to look at it. Maybe there is a general answer to that problem because it would be quite a lot of work to rename all objects and I really would lilke to know what went wrong for the next time.

Looking forward to your suggestions.

 

What do you mean by change the object name? In the code or in the terminal's objects list ?

Do you have more than 1 EA/indicator on the chart that are using the same object name? If so, the other EA/indicator may be deleting or moving them. Run the indicator on a chart with no other EA/indicators attached and see if you still have the problem.

Maybe you could show the relevant sections of code where you create and/or delete the objects.

 
void create_obj(string obj_name, int x_dist, int y_dist, string dbl_var, int font_size, string font, color color_)
      {
      ObjectCreate (obj_name,OBJ_LABEL,0,0,0,0,0);
      ObjectSet    (obj_name,OBJPROP_XDISTANCE,x_dist);
      ObjectSet    (obj_name,OBJPROP_YDISTANCE,y_dist);
      ObjectSetText(obj_name,dbl_var, font_size, font, color_);
      }

This is the initial function. Then I create the objects in the code later like this:

create_obj("Intraday", Movers1[5], yaxis, DoubleToStr(ADR_Faktor,2), Font_Size, Font, color1);

If I would change "Intraday" to "Intraday1" for example the object would show up again.

Now I found out (via ObjectFind()) that all my objectnames from the code already exist. I am not sure what I have changed. Even if I comment all create_obj lines out they still are found.


EDIT: It's the only indicataor running.

 

I don't get it. I commented the COMPLETE code out, except

Print("Object found? " + ObjectFind("Intraday"));
and all objects once created still can be found.
 

Could they be hiding behind another object?

I think MT4 arranges the objects based on name, so changing the name could bring it in front of other objects.. I assumed it was alphabetically from the first character but I haven't found out yet. Did you try creating the object with the name: Intraday1 ?

As for the last comment... are you deleting the objects in the DEINIT special function? If not, you will be finding the leftovers from the last time you ran the indicator. (removing the indicator doesn't remove the objects it has made, unless they are in the indicator's subwindow)

 

Create your labels in init() and delete them in deinit()

Then all you need in start is ObjectSetText

 
Thanks guys. I'll consider to rewrite the code like GumRai suggested. For now I found deleting the objects right in the beginning of the start()-function is doing the trick as well.
 

Its not always good to use functions. Looking at the little bit of your code, you are probably giving yourself more work by creating the objects using a function. The best way is to create all your objects in the init function, give them values in the start function and delete them in the deinit function. This also saves memory because the parameters that are not changing are only created/set once and only the ones that change go in the start function to be modified at every tick then finally the object is deleted when you remove the ea. i.e.

int x_dist=200,y_dist=15;
color color_=Red;
string obj_name="Intraday";

int init()
{

      ObjectCreate(obj_name,OBJ_LABEL,0,0,0,0,0);
      ObjectSet(obj_name, OBJPROP_CORNER, 1);
      ObjectSet(obj_name,OBJPROP_XDISTANCE,x_dist);
      ObjectSet(obj_name,OBJPROP_YDISTANCE,y_dist);

return;

}

int start()
{

...
ObjectSetText(obj_name,dbl_var, font_size, font, color_);

return;
}

int deinit()
{

  ObjectDelete(obj_name);

return;
}
 
tonny:

Its not always good to use functions. Looking at the little bit of your code, you are probably giving yourself more work by creating the objects using a function. The best way is to create all your objects in the init function, give them values in the start function and delete them in the deinit function. This also saves memory because the parameters that are not changing are only created/set once and only the ones that change go in the start function to be modified at every tick then finally the object is deleted when you remove the ea. i.e.

What happens if the Object is deleted manually from the chart by mistake ?
 

There are two ways to manually delete objects from a chart and there are two most unlikely mistakes one can make in mt4 namely:

1) I accidentally double clicked on an object taking less than 5% of the chart area and clicked the delete button.

2) I accidentally left clicked on the chart causing a dropdown to appear and accidentally selected chart objects option then accidentally clicked on an object check box and accidentally moved the mouse cursor to the delete button and clicked on it

 
RaptorUK:
What happens if the Object is deleted manually from the chart by mistake ?


Also what if you put everything in start function then someone wants to unclutter the chart by manually deleting some chart objects but they keep coming back or maybe you sell someone an indicator but he wants to remove the objects they dont need?