Is there any ObjectRename or ObjectCopy capability? How can I program this...

 
Hi all,

I need some programming help. What I want to do is kind of trivial to do if done graphically, but I haven't figured out how to do it inside an indicator program.

1. Rename objects:

I want to rename chart objects such as an OBJ_FIBO so that it has a different "ObjectName". (NOT ObjectDescription which is different).

Graphically, if I place a fibo object on my chart and select it, it is trivial to change it's ObjectName:
Select the object. Right-click. Fibo Properties -> Common tab -> Name (edit, then OK to save. Unless another object by the new name exists, it will save it, no problem.)

However, I cannot find an appropriate MQL function to do this. I can see "ObjectName" which retrieves the name. But there is no "ObjectRename" nor "ObjectSetName" nor do I see that ObjectSet can be used for this purpose, nor anything else. The ObjectSetText changes the "Description" field for the object just fine, but again, that's not the "Name" field.


My only workaround would seem to be to do an ObjectCreate, and copy every single object property value (which seems rather tedious to me), and when finished creating the new object, delete the old object. Is there a better way?


2. Copy objects:

I'd also like an easy way to Copy an object with all its properties intact.

Graphically this is trivial to do as well. (Actually it's a neat trick that I just recently learned). In a chart, select an object. Now hold down the Control key at the same time as a left-click over that object and drag it elsewhere on the chart. This copies the object!

However, as before, I can find no easy MQL function to do this. There is no ObjectCopy function. Once again, I'm left with my workaround which is to ObjectCreate a new object and copy each of the many property values over from the original object to the new.

Is there an easier way?


3. If I still have your attention, let me explain my idea, and you can help me to know if there's any serious drawbacks to it.

I'd like to create objects graphically and then edit the Description to add a keyword. I'll add an indicator that in the "start" function (every tick), it will run through a foreach-object loop. If it detects the Description keyword, it will modify some properties on that object. However, when finished, change the NAME of that object to add a new keyword. Then the next time through the loop as it detects the Description keyword again, it will first check the Name field and if the same keyword exists there, it will leave the object alone.

By this method, I'd like to use the Description field to give commands to modify the object, but I'd like to use the Name field to store some of the key data, including my keywords as well as time/value points.

I know I'm limited to 62-characters for both the Description and Name fields, and I know that every Object "Name" must be unique. I am unaware of other other object string property which I could use for this purpose but if there is, please tell me more.

My concerns before I do this:
a. Will I blow up my virtual memory if I delete/create too many objects?
Because this is every tick, will I radically slow down my session if I get a lot of objects?
b. Is there a more efficient method to determine whether any OBJECT has changed since the last time a program ran? Every new bar is too slow. Every new tick is excessive. I need something in between... alas.

4. While we're on the topic, I'm also looking for some way to pass chart objects between charts. I presume this means I must us an indicator to write out object descriptions to some file from one chart, and read that file using an indicator running on another chart. However, I'd also like bi-directional capabilities, so reading and writing from the SAME file simultaneously isn't possible, so... any suggestions? I guess each chart could write its own unique file, but read every other file.

Are there any programming examples of this kind of idea?


Thanks in advance for any hints or solutions,
Pips4life (Kent)
 

1 no, only delete it and creat another

2 no

reference Objectset(....)

 
Makes me wonder, what are you REALLY trying to do?
 
phy:
Makes me wonder, what are you REALLY trying to do?

For example...


I have several different and specific ways to draw fibo lines. On each set I vary the color and fiblevels. It's a big pain to modify all the levels and colors every time I place a fibo of a different set than the last time. A workaround is to have a 2nd chart open that has an example of each kind of fibo set, and then select the object, right-click for properties, then "OK". That essentially makes that object my current set, so back in my chart of interest, when I place a new fibo object it will be of that new set type. But to do this every time, going back and forth between charts is a big hassle. Far easier it to draw a fibo object then modify the Description to add a keyword, and voila, the indicator changes the colors/levels/etc. according to my keyword. It's very easy to do, and I don't need a 2nd chart open with reference objects.


However, why bother to change the ObjectName? There are many reasons. As one example, there are times when I'd like to toggle a fibo between a) it's normal placement, and b) a completely vertical line. A vertical fibo is narrow, and it greatly reduces chart clutter while I look mainly at something else, or perhaps when I look at a dozen all-vertical fibo objects... but eventually I *will* want to re-expand that fibo to "a)", it's normal placement. Therefore... I need a way to store the T1/P1 and T2/P2 coordinates. While I could use the Description field, I happen to like using "Show Object Descriptions" on my charts; therefore, using the Description to store such information would add significant clutter to the chart. Far better to use the ObjectName field.


In either case (Name or Description fields), I know I'm limited to about 62 usable charaters, but it's enough for my purposes.



Another example...


I like labelling Elliott Waves on my charts. Right now, it's pretty tedious to place labels of different colors/sizes on a chart when those sizes are constantly varying. I'd like to store the specific swing-high or swing-low time that the label is nearby, but the only place to store such info is as part of the ObjectName, because the entire Description for a text-object is displayed, so I can't clutter up the Description.


Eventually, I'd like to be able to direct an indicator to auto-draw specific fibo sets based on the specific swing-highs and swing-lows that my text lables are *near* (The labels may not be exactly on top of the Time/Price coordinates I want).


By the way... another approach I've thought of -- which is not mutually exclusive from my current approach at all -- is to create avisual array of objects on my chart from which I select specific objects and then use "Control" plus left-click-and-drag to copy the object from the array to elsewhere on my chart. When copied, the object Description stays the same, but the new object gets a new ObjectName (which is fine, because I can modify it). If you are familiar with the vHandsTrade/vHistory/vTerminal tools (a method of back testing with MT4), you will recall there is an array of trendlines. The user causes a buy/sell/set_SL/set_TP action by dragging an object from that array onto his chart. What I'm imagining is a similar kind of visual array of objects (i.e. various fibo sets, expansion sets, and most importantly, a set of Elliott Wave labels to drag and drop).




It's rather ambitious given the limiations of the MQL4 language, but I'm making progress. Even tougher is the fact that I'm more of a hacker, not a pro-programmer (although I've worked miracles on other projects by plowing through each issue). Does that help clarify what I'm attempting to do? Please help if you can. Thanks.

 
phy:
hmm...

I don't see any mention of scripts above.


They might be useful in some of the things you want to do.


Toggle Fibo Visibility state

Drop objects or sets of objects onto chart.

Delete specified object sets.

and so on.

 

Hi

You can Create new object with different name but current properties.

then delete the other one.

I have tried it as needed to be remained with object on the chart while running the tester. this enabled me to review tester chart at later stage with all object created while running it.

 
You can also use ObjectFind() function to find an object and then when it's found use ObjectDelete() function and after that you can (re)create the object again.