Expanding my EA to multiple currencies

 

I programmed a very neat EA that works well an a couple of pairs. Now instead of pulling it onto every chart I would like to have one EA run and handle multiple pairs at the same time. So far so good but there is one remaining issue that I have: In the documentation about getting values from indicators (iCustom, iMA, ...) all the examples are always so that you define a global int variable. For example:

//Indicator Handles declaration
int hMA, hTEMA, hATR, ... = INVALID_HANDLE;

//List of currencies to trade (array filled on OnInit())
CArrayString currencies;
string pair;

//Indicator Handles definition
hMA = iMA(pair, NULL, MAPeriod, 0, MODE_SMA, PRICE_CLOSE);
if(hMA == INVALID_HANDLE){Print("Error creating Moving Average indicator");}
ChartIndicatorAdd(0, 0, hMA);

//more handles defined here
.
.
.

//Pseudo Code for my OnTick() function
void OnTick(){
        int size = currencies.Total();
        for(int i = 0; i < size; i++){
                pair = currencies[i];
               
                //Do stuff for this currency here

        }
}

Now, how can I call the indicator with a different pair as an argument every time I iterate over the list of symbols? I think the way that I am doing now, I cannot do that since the indicator handle is just an int variable and not a funciton. So, is the solution to define a function with the symbol as an input argument and it creates a new handle every time it gets called? Is that how one would do that?

Or would I rather create as many indicator handles for each indicator as I have symbols to trade?

Bit lost here. Thanks for any help! Let me know if you need more code, I just thought I keep it as simple as possible since I am more asking for the general concept rather than actual code.

 
osterchrisi :

I programmed a very neat EA that works well an a couple of pairs. Now instead of pulling it onto every chart I would like to have one EA run and handle multiple pairs at the same time. So far so good but there is one remaining issue that I have: In the documentation about getting values from indicators (iCustom, iMA, ...) all the examples are always so that you define a global int variable. For example:

Now, how can I call the indicator with a different pair as an argument every time I iterate over the list of symbols? I think the way that I am doing now, I cannot do that since the indicator handle is just an int variable and not a funciton. So, is the solution to define a function with the symbol as an input argument and it creates a new handle every time it gets called? Is that how one would do that?

Or would I rather create as many indicator handles for each indicator as I have symbols to trade?

Bit lost here. Thanks for any help! Let me know if you need more code, I just thought I keep it as simple as possible since I am more asking for the general concept rather than actual code.

In OnOnit (), you must create indicator handles for the required symbols in advance. For example for EURSD, H1 and USDJPY, H1.

And then, in OnTick (), using CopyBuffer, get the indicator values.


The main thing: in MQL5, the indicator handle MUST BE CREATED ONCE - and this is done in OnInit.

 
osterchrisi:

I programmed a very neat EA that works well an a couple of pairs. Now instead of pulling it onto every chart I would like to have one EA run and handle multiple pairs at the same time. So far so good but there is one remaining issue that I have: In the documentation about getting values from indicators (iCustom, iMA, ...) all the examples are always so that you define a global int variable. For example:

Now, how can I call the indicator with a different pair as an argument every time I iterate over the list of symbols? I think the way that I am doing now, I cannot do that since the indicator handle is just an int variable and not a funciton. So, is the solution to define a function with the symbol as an input argument and it creates a new handle every time it gets called? Is that how one would do that?

Or would I rather create as many indicator handles for each indicator as I have symbols to trade?

Bit lost here. Thanks for any help! Let me know if you need more code, I just thought I keep it as simple as possible since I am more asking for the general concept rather than actual code.

you could group them into array of struct and load them via function overload
Reason: