Download MetaTrader 5

Can 1 EA monitor & trade multiple currency pairs from within one chart? - page 2

To add comments, please log in or register
Tjipke de Vries
6372
Tjipke de Vries  
angevoyageur:

If you don't want to reply to his question, don't reply, it's simple. No need to offend people.

And believe me, it's available for me too, if I posted everything I want to post, I have 1000 rating points more, at least.



if he had done some research and looked in Code Base then he had find for example https://www.mql5.com/en/code/11176

and you can find more such examples the way he is asking now is looking to me and i guess to others

that he doesn't do enough to learn how to code and wants to get from others to code for him to get examples how to do trade one EA different symbols

without doing any attempt himself...

Like CodeMonkey wrote to xennon

'The problem here isn't that it cannot be done, it's that you haven't bothered to even try and do it. '

.

if xennon gets doing this replies he doesn't like then it is also his way reacting to it a wrong way

think you understand the situation how i see it...

Alain Verleyen
Moderator
32429
Alain Verleyen  
deVries:


if he had done some research and looked in Code Base then he had find for example https://www.mql5.com/en/code/11176

and you can find more such examples the way he is asking now is looking to me and i guess to others

that he doesn't do enough to learn how to code and wants to get from others to code for him to get examples how to do trade one EA different symbols

without doing any attempt himself...

Like CodeMonkey wrote to xennon

'The problem here isn't that it cannot be done, it's that you haven't bothered to even try and do it. '

.

if xennon gets doing this replies he doesn't like then it is also his way reacting to it a wrong way

think you understand the situation how i see it...

Of course, I agree.

But I also agree that if someone replies, there is no need to offend the OP (or any other user). I think this forum needs a better atmosphere.

Xennon
86
Xennon  
deVries:

xennon: is registrated from januari 2012 and now comes here with this Question ??

looks to me it's time for him to do some research by reading and learning

if he wants to make that EA then he has to come with his attempt if he gets problems making it

it is possible .... after more then 2 years he knows that now for sure


Yeah 2 yrs so what?! Does not mean I have been actively messing around in MQL does it? - in fact my collective experience with MQL is probably less than a month, TOTAL. I suggest you either contribute something positive and useful or xxxx. What a stupid and idiotic statement to make.
Alain Verleyen
Moderator
32429
Alain Verleyen  
xennon:

Yeah 2 yrs so what?! Does not mean I have been actively messing around in MQL does it? - in fact my collective experience with MQL is probably less than a month, TOTAL. I suggest you either contribute something positive and useful or xxx. What a stupid and idiotic statement to make.

I already advice you to watch your language. This is my last warning.

Thank you.

Tjipke de Vries
6372
Tjipke de Vries  
xennon:

Yeah 2 yrs so what?! Does not mean I have been actively messing around in MQL does it? - in fact my collective experience with MQL is probably less than a month, TOTAL. I suggest you either contribute something positive and useful or xxxx. What a stupid and idiotic statement to make.


the example from codebase i pointed out ???? https://www.mql5.com/en/forum/149766/page2#915892

Daniel Petrovai
440
Daniel Petrovai  
xennon:

I am wondering is it's possible to have a single EA running on any currency pair, but have it monitor multiple currency pairs and respond to triggers as they arise in each pair.

Essentially I want a EA that will poll all pairs of interest, test pre-configured criteria on each one and respond with buy/sell/close/alerts as required.

I suspect this cannot be done, but would be interested to hear if anyone has any ideas as to how to achieve this without having to open a lot of charts and applying the EA to each chart separately mainly in the interest of efficiency (better to have 1 block of code instead of a dozen?)


Thx.


My money would be on a string array for the symbols and then go trough a loop for all symbols of interest

Something like

string nameArray[]={"EURUSD","...","USDJPY"};

then

for(x=numberOfSymbols;x>=0;x--)
   {
   string symbol=nameArray[x];
   CustomCondition(symbol)
   ....
   .....
//or something like that
Noddy
9
Noddy  
xennon:

I am wondering is it's possible to have a single EA running on any currency pair, but have it monitor multiple currency pairs and respond to triggers as they arise in each pair.

Essentially I want a EA that will poll all pairs of interest, test pre-configured criteria on each one and respond with buy/sell/close/alerts as required.

I suspect this cannot be done, but would be interested to hear if anyone has any ideas as to how to achieve this without having to open a lot of charts and applying the EA to each chart separately mainly in the interest of efficiency (better to have 1 block of code instead of a dozen?)


Thx.

Hi xennon,

The short answer to your question is yes.

I've thought of doing something similar but haven't got around to coding anything yet so I'll give you the basic outline of how I would structure the code but not specifics as it would probably be better if you researched how to code each part yourself and referred to the codebase and other sources as coding examples as a learning exercise as it will help you more in future code writing than simply copying code from examples and pasting a solution together without really understanding what is going on and why, plus it will help in debugging code errors. Although the codebase can be confusing if you are unfamiliar with coding as some terminology can be difficult to follow.

Also as my idea hasn't been tested or implemented yet so there are possibly better ways to code it or bugs I have not foreseen as I am not a master coder by a long shot and am quite rusty in general so if anyone has any suggestions I am all ears and if there are errors please don't shoot me down.

The general idea is to use the millisecond timer event as the OnTick event will only work for the chart it is attached to so ticks for other currency pairs will not generate a tick event and the EA won't run but the millisecond event timer can trigger multiple times per second and monitor for price changes. Also use three arrays, one to store the strings of the symbols you want to use and another to store the price data.

I'll try to explain it a little. The array nameArray will store each symbol as an array but more importantly the element of the array can be used to set the position for other the other two arrays as they cannot use a string to locate a position in an array but the index value can. As ticks for each symbol are received at different times the data written to the PriceArray will not all be at the same time as some symbols are more active at different times so the second array stores the index for the PriceData array so it can be written to quickly without overwriting any past price data. The third array will write the necessary price data you require.

The code is a combination of code and english with what needs to be added. It is very simple but should provide you with a starting point for your idea. There are numerous gaps such as when to deal with the arrays when they reach the end but this is all part of the learning curve. I suggest getting the code to work with one symbol and then two, and so on to allow you weed out and fix any bugs in the code. As I've said this is just a rough draft so use it as such and improvements are possible, for example, you can use a Struct data type or an object instead of the three arrays to store the tick data but this design is a little simpler to start with and you can look at Structures and Object-Orientated programming at a later stage of coding.

I have tried to be clear but this may be very confusing for you so if you have any further questions about clarity let me know and I'll help where I can but unfortunately I do not have time to code anything like this.

Here is the pseudo code,

// OnInit ()
    {
     string nameArray[]={"EURUSD","...","USDJPY"};                         // As suggested by thrdel. Creates an array with currency pairs
     int TicksRecorded [# of symbols monitored];                           // Records the required position in the PriceData array to write the next tick data to for each symbol
     double PriceData [# of symbols monitored][Ticks][data to record];     // Stores price data for each symbol required for as many ticks as required

     Create the timer and set an appropriate interval
     Open a file to save data if required for future use
     
     for (x=0; x < # of symboels; x++)                                     // Get all prices for all the symbols you want and store them in the first position of the Ticks and data to record dimensions
           {                                                               // Also adapted from thrdel's code example
            PriceData [x][0][0] = Ask;
            PriceData [x][0][0] = Bid;
            ... whatever else you want to record
           }

// EventSetMillisecondTimer()
    {
     Refresh all price data for all symbols
     for (x=0; x < # of symbols; x++)                                     // Get all prices for all the symbols you want and store them in the first position of the Ticks and data to record dimensions
           {
            if ((current Ask != to previously recorded Ask for that x) or (current Bid != to previously recorded Bid for that x)... and every other price data you want)
                {
                 TicksRecorded [x]++;                                    // Increments the position in the PriceData array holding the latest tick data for that symbol
                 PriceData [x][TicksRecorded[x]][0] = Ask;
                 PriceData [x][TicksRecorded[x]][1] = Bid;
                 ... and whatever else you want to record
                 Flag to indicate a new tick has been received set to true
                }
            if (new data)
                {
                 Set new data flag to false
                 Do custom action
                }
           }
     }

// OnDeinit ()
     {
      Kill the timer
      Save data to a file if required
     }
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI  

I simply use Global Variables to allow my ea monitor/make trades from within one chart.

Though you have to make your ea a bit more robust and does not specific to one chart.

12
To add comments, please log in or register