Interaction with many charts

 

Hi!

I have a question about how an expert interacts with many charts at the same time.

I have this expert, which closes every order as soon as certain condition is met. The thing is that this is signaled through a variable, and, once every order

is closed, I reset this variable to "stop closing" mode... however, there is another chart that should keep closing them, but since the variable was reset and

global variables seem to be shared throughout every graph, in one chart every order is closed, but in the other one some orders stay open.

So, the question is, how do global variables interact between charts, with the same Expert Advisor? And, for this particular problem I discuss here,

do you have any idea on how to solve it?

Thanks in advance!

 

I think I see what your problem is . . . . there are probably numerous ways to sort this issue, this is what first springs to my mind:

Imagine you have 3 EAs trading, you want to be able to tell them all to close their orders and you also want to know when they have done so. Use a GlobalVariable and set it's value as follows:

to stop all 3 EAs: binary 0111 (decimal 7)

to stop EA 1, 0001 (decimal 1)

to stop EA 3, 0100 (decimal 4)

Now the bit that addresses your issue . . . as each EA completes closing it's orders it sets it's "bit" to zero, like so:

once EA 1 has closed all it's orders, 0110

once EA 1 and 3 have closed their orders, 0010

once all 3 EAs have closed their orders, 0000

This way the controlling EA knows when the EAs that close the orders have completed . . . you will probably need a 2nd Global Variable for overall place/Don't place order signalling.

 
changowero:
So, the question is, how do global variables interact between charts, with the same Expert Advisor?

If you mean global as in outside function definitions (that includes externals,) each EA's is independent.

If you mean Globals all are shared.

 

@RaptorUK

That's a great method, I will check it out! Thanks!

@WHRoeder

Yeah, I meant global as "Global scope variables", within the EA. So, if in my code I have some:

OrderSend(...OP_BUY...)

buy_count++;

That variable, buy_count, will be +1 for every chart? Or only for the one where that order was sent?

 
Just to be clear, in what I wrote above I meant https://docs.mql4.com/globals
Reason: