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

 

I need to make the EA work with only "one instance". I.e. I attach it to any chart for the first time and it works. If I then accidentally or intentionally attach it again to another chart, the second attachment should recognize that it's 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 not clear which one will work first with its init, where this global variable could be created.

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

 

Well recompiling is crutchy, but solvable, but what to do in case of terminal restart...

And global variables are bad, because if terminal crashes, having previously written global variables to file, then everything will crash.

Alternatively, you can keep a handle of something.

 

TheXpert:

.... anything

that's the question :((
 
but just not to chain the EA twice to the chart, is that not feasible?
 
Techno:
but just don't link the EA twice to the chart, is that impossible?

I need a WARRANTY that neither I nor anyone else will do it accidentally or deliberately ;)

Just imagine: the EA receives 'external' commands to open orders. Even one extra copy is (theoretically) one extra order.

 
ForexTools:
that's the question :((

No, that's the implementation details, the main problem is restarting and recompiling.

Oh, there's a topic, just need to check -- is the EA restored when restarting and recompiling, if before it crashed, for example, on division by 0?

If not, that's the way to go.

 
TheXpert:

No, that's an implementation detail, the main problem is reloading and recompiling.


Recompiling should not be the problem.
 
PapaYozh:

The problem should not arise during recompilation.

how come? let's say we have three copies of the EA (without any tricks - just clean ones). you recompiled it. the "command" went to the terminal. the EAs started to initialize.... in what order shall they be re-initialised?
 
ForexTools:

let's say we have three copies of the EA (without any tricks - just clean ones). you recompiled it. the "command" went to the terminal. the EAs started initialing.... in what order shall they be re-initialised?
then it turns out that one of them was trading, but after the reboot, the right to be the leader will be given to the other and the first will lose this right, so what difference does it make if they are the same? the main thing is that one traded. Use a global variable and that's it. In the inite function write a random expectation for each EA to sleep(), the one who first wakes up, counts the global variable and deletes it, at deinit restores it again. The first one to count and delete will work. In short, you generate a random number for sleep()
 
ForexTools:

let's say we have three copies of the EA (without any tricks - just clean ones). you recompiled it. the "command" went to the terminal. the EAs started initialing.... in what order shall they be re-initialised?

And you don't rule out having the same graphs? I.e. should the EA start on 2 charts with the same symbol and the same period be processed?
 
Techno:
Then it turns out that one of them traded, but after reloading, the other one will get the right to lead and the first one will lose this right, and what difference does it make if they are the same? Use a global variable and that's it. In the inite function write a random expectation for each EA to sleep(), the one who first wakes up, counts the global variable and deletes it, at deinit restores it again. The first one to count and delete will work. In short, you generate a random number for sleep()

By the way, yes. If 2 instances of EA are unacceptable, then it doesn't matter which EA starts first.
Reason: