Sharing an array between all instances of EA's?

 

I wish to create an array:

const int profitsSize = 32;‌

double potentialProfits[profitsSize];

Is it possible to share this array with all instances of my EA?

It's so the EA's can decide which currency pair to open, the most profitable one.

I also need to share an int‌ too(profitIndex) so each EA knows which array index to bind to. And also set the profitIndex to 0 only once.

for example:

int profitIndex;
...
// when first EA loaded
profitIndex = 0;

...
// set bindProfitIndex when each EA is loaded

int bindProfitIndex = profitIndex++;
...

// set potential profit
potentialProfits[bindProfitIndex] = ...;

Can EA's use pointers as in c++?

for example:

double *potentialProfits[32];‌

Thanks. ‌

 

Not to worry, I doubt 2 EA's would want to open at the same time (within a click) very often.

Though I may find other uses for sharing variables so is it possible?‌

 

To declare a non  dynamic array you can't use a variable! Either use a number arr[32] or a 'defined' number: #define arrSize 32  ... arr[arrSize];

Or you use a dynamic array and then you can use a variable to re-size the array: arr[]; ....‌ ArrayResize(arr, profitsSize);

 
Carl Schreiber:

To declare a non  dynamic array you can't use a variable! Either use a number arr[32] or a 'defined' number: #define arrSize 32  ... arr[arrSize];

Or you use a dynamic array and then you can use a variable to re-size the array: arr[]; ....‌ ArrayResize(arr, profitsSize);


Thanks, can I share it across all instances?

Also how can I share variables between Indicators and EA's?

Thanks.‌

 
I know I can use iCustom to access indicators buffers from the EA, but how can I access variables? Is it possible?
 
paulgriffiths: can I share it across all instances?
  1. No you can't.
  2. You can share a individual doubles via Global Variables of the Terminal - Reference on algorithmic/automated trading language for MetaTrader 5
  3. Anything else will be files, pipes, shared memory, etc.
 
paulgriffiths:

Can EA's use pointers as in c++?

for example:

double *potentialProfits[32];‌

Thanks. ‌

Pointers in mql5 are not really pointers (you can't access memory directly).

Also they are available only for object (class instance) not for basic types (int, double...).‌

 
Alain Verleyen:

Pointers in mql5 are not really pointers (you can't access memory directly).

Also they are available only for object (class instance) not for basic types (int, double...).‌


I see, thanks anyway. Just checking.
Reason: