Undo created object?

To add comments, please log in or register
Nikolay
193
Nikolay  

How can I undo creating an object (HL, VL, Trendline) after pressing a button to create it? (not by calling ObjectCreate, so I do not have the object name)

My current thoughts and questions:

  1. There is a menu "Charts->Objects->Delete Last", but it has no effect after a) I draw a HL and chose it or b) if I choose two HLs and chose it. How does it work?
  2. MT4 gives those objects names in the following format <OBJ_NAME> <OBJ_NUMBER>, e.g. "Horizontal Line 55790". This number seems to increase after every object I create by pressing a button. Is that correct?
  3. If 2) is correct, maybe I could write a function that searches all object with the above mentioned format, finds the one with the highest number and deletes it. Do you see any potential issues and has anybody already done that?

Thank you!

Nikolay
193
Nikolay  

if the chart is fresh, then the number get higher and higher as objects are created, but if the chart is old/reopened (I do not know when exactly) the numbers of the newly created objects may be lower than the current highest number.

So 2) is not exactly correct ...

Does anybody know how the last created object can be identified at anytime working with the chart?

Keith Watford
Moderator
20526
Keith Watford  
I've never had reason to use it, but you could loop through the objects and find the last using

OBJPROP_CREATETIME

Nikolay
193
Nikolay  
oh, great! Somehow I missed that property! Thanks :)
Thierry Ramaniraka
542
Thierry Ramaniraka  
In the same kind of idea, is there a function to undo "ObjectDeleteAll" (called by delete button and called by undo button) ?
ObjectsDeleteAll - Object Functions - MQL4 Reference
ObjectsDeleteAll - Object Functions - MQL4 Reference
  • docs.mql4.com
[in]  Prefix in object names. All objects whose names start with this set of characters will be removed from chart. You can specify prefix as 'name' or 'name*' — both variants will work the same. If an empty string is specified as the prefix, objects with all possible names will be removed. Indexing of chart subwindows (if a chart has...
To add comments, please log in or register