How to ensure that the EA only works on the chart where it was first dropped - page 4

 

This is probably how it works:

Start, create a global variable and an object on the chart (somewhere outside the chart, so as not to accidentally delete it by hand) and "write" one common key in both of them (obtained by GetTickCount, for example).

Re-runs on other charts check global variable presence. if it exists - search for an object with the same key on OUR chart. if it's not found - other chart - don't work and yell with alert that it's a re-run!

Since chart objects and global variables must survive restarts and recompilations - the check will always work correctly.)

 
ForexTools:

This is probably how it works:

Start, create a global variable and an object on the chart (somewhere outside the chart, so as not to accidentally delete it by hand) and "write" one common key in both of them (obtained by GetTickCount, for example).

Re-runs on other charts check global variable presence. if it exists - search for an object with the same key on OUR chart. if it's not found - other chart - don't work and yell with alert that it's a re-run!

Since chart objects and global variables must survive restarts and recompilations - the check will always work correctly.)

Sometimes objects are not saved if the terminal has crashed.
 
ForexTools:

The Expert Advisor should work with only "one instance". I.e., the first time I attach it to any chart and it works. If I then accidentally or intentionally attach it again to another chart, the second attachment should recognize that it is already running and do nothing.

Leaving the label in a global variable probably won't work. If I have two EAs attached and I recompile its text, it's unclear which one will work its init first to create this global variable.

Who can suggest what? Any thoughts on how to do this?


And if at initialization to open file to write, at deinitialization to release it. Logically, a new instance of EA cannot open a file that was opened for writing earlier. If, for example, five iterations, we consistently get an error of opening a file for writing, it means that one instance of the EA is already open.

 
exhumer:
A new instance of the EA will not be able to open a file that was previously open for writing.

after the terminal has crashed and restarted, the file will be available to the first person to open it, not the first person to reset it :(

Once again, I repeat: you need a specific chart - a specific Expert Advisor.

 
ForexTools:

your idea doesn't work.

What do you mean it doesn't work? While this is a hollow assertion.
Especially since you have nothing but an idea (let alone a "concrete recipe")

what can i infer from your "solution" ??? ;)

It is exactly an idea. If you do not have enough knowledge to understand how to check it, then write so. Actually you did, but you wrote it as a claim. At least the remark "what can I code on your "solution"? ;)" looks exactly like a claim. And then for some reason a set of trivialities

"should" doesn't mean "will", "there" is "where"? if "didn't work"

- how can you give advice on untested solutions?!

Look, if only proven solutions were offered, you would still be looking for roots with a stick. Whose problem is this, mine or yours? Why on earth would you qualify the suggestion of an idea as a recommendation of a solution?

From my point of view the question statement is: I give you an idea, you test it, if it works you inform me that it works, by way of a minimal thank you.

P.S. Man, you should have looked into one chr file out of curiosity, as you pretend to be a pro at working with MT.

 
TheXpert:
Then bluntly file as a locker and no problem.
Why not use this, the simplest option? The Expert Advisor creates a control file and checks if the file exists before doing so. If the file of the same name already exists, the Expert Advisor will not start. If the EA exits the chart correctly, it will erase the file. If a crash occurs, the remaining file blocks the launch of any instance of the EA and is deleted manually in order to continue working.
 

Candid:

Whose problem is this, mine or yours? Why on earth would you qualify your suggestion of an idea as a recommendation of a solution?

Because that's exactly what I asked for in my first post - that's why I took your idea as such.

You seem to pretend to be a pro at working with MT.

that's why I see the validity of many "ideas" even DOTO as their..... ;)

if i'm wrong about you - write some EA code that does nothing but prevent your second copy from running. check that it really works when recompiling and restarting the terminal and post the code here - everything will fall into place ;)

 
granit77:
When a crash occurs, the remaining file is blocked by....

there are two charts, one of them has a working EA holding the file, and the second one has a copy of EA not working due to a locked file.

the terminal is down or closed.

(re)start the terminal. on it two EAs start checking to read the file. is there any guarantee that the real first one will grab it first and not the one that was blocked last time? :(

For the third time I repeat: I need a link between CHART and EXPERT, but not blocking one Expert Advisor by another one.

 
granit77:
Why not use this, the simplest option?
No, no, that's only if it doesn't matter which instance to run.
Reason: