Isn't exactly the usage of OBJPROP_ZORDER ?
Why placing objects on top of each other, seems weird to me.
traderathome, I think I can help. Like you, I've been banging my head with this one too. Sometimes traders want info drawn on their chart - that is why there is the ability to create text and labels, otherwise what is the use, remove them from MT4 altogether if no one needs them, right? Having them alone is not enough. Like you mentioned - pleasing to the eye is important too. I completely understand you here!
We need to work around, because things work much differently now, even if makes absolutely no logical sense. I will address that one first.
First, realize that no matter how you name them alphabetically or what order you create them, anytime a user closes MT4 and restarts, the order of creation, etc won't matter because the objects will switch order on you!!! See ignored thread here that clearly points this out! https://forum.mql4.com/61480
Solution is to delete the objects using UninitializeReason(), then recreate them later. Thankfully REASON_CLOSE has been added !! This was not true in older builds. https://forum.mql4.com/58052
Now, I know what you are thinking (like myself) and that is "I am storing info on text objects, if I delete them I lose information".
So, this is what I am doing.
1. Create your objects in the order you wish them to appear.
2. OnDeint(), UninitializeReason() REASON_CLOSE, remove what you absolutely do not need to remain on chart, although keep everything that is storing info.
3. When client reopens MT4, pass the stored Object Description information to a string, delete the Object that was storing information, then redraw it again (in order it should appear) and pass your string value to the new recreated object that is taking the place of the one you deleted. Name can be the same as original. This can be achieved quickly on start up (or single tick). Trader won't notice.
I understand you are frustrated like I was, but hopefully this workaround helps you. Kind regards.
So the thread is about placing multiple objects in the same location and establishing which object will be the on top object when clicking on them, well why didnt you say that OP ? lol
I believe angevoyaguer is correct, OBJPROP_ZORDER allows to give one object priority over the others. When clicking on objects that are stacked/layered/on top of each other the one with the higher priority will respond.
I've just spent hours trying to use OBJPROP_ZORDER so the correct object can be clicked - without success. Changing the zorder makes no difference. Strangely when the correct object is clicked the Chart Event that is generated can be for an objects many pixels away on the y - axis.
Also create order of the object makes no difference to which object appears in the Chart Event click function.
I have found that clicking on a label has no effect if the label is drawn on top of a rectangle label. The chart event will always be that the rectangle label has been clicked.
This means that you need to back the label with a smaller rectangle label or use an Edit object instead.
I've found 2 workarounds for ZORDER not working:
1. remove less important and conflicting objects!
2. when clicking a object the wrong object is often reported in the ChartEvent click function. However if the object is dragged (even for only a pixel) the correct object is reported in the ChartEvent click function.
To add comments, please log in or register