Running code(s) when third party EA is running

 

Hi guys and thank you for reading my thread.

I am very new to automated trading and have been spending time on the MQL5 website reading articles.  I have also been reading through the MQL4 book.  I think I understand the content reasonably well so far and have had a go at creating dummy "alert type" scripts and EAs to start my learning.  Being in the initial phases of learning Im finding that the more I read the more questions I have about MQL4!  My problem is that I have a very specific query to which I think I am unlikely to find the answer in the book or on the forums, and wondered if I could take some advice to make sure that my project "gets off on the right foot".

I am using the MT4 client.  My MT4 client is (or will be) subscribed to a third party EA through the Tools --->  Options ---> Signals Tab.  The client then automatically places copy/mirror trades based on instructions that come from the signal.  My understanding is that these signals are not "attached" to a particular chart and the signal can give an instruction to buy or sell any currency pair at any time.

I wish to write two programs that do two different tasks.  Lets call them program A and program B.

The intent of Program A is that every time an instruction comes from the third party signal to buy or sell whether its opening and order or closing an order, the program will detect that a change to the status of open orders has occurred, and will send a record of the latest action to a text file or excel spreadsheet with basic info about that order (i.e. datetime stamp, currency pair, open/close price, volume).

The intent of Program B sounds a little trickier (to me at least!).  I would like that when an instruction is received from the signal to open a new buy or sell position, the MT4 client logs every tick (or maybe the price at 1 second intervals, or whatever) until the order is closed.  Each datapoint would contain basic info such as the datetimestamp (or time since position was opened), the current price, etc.  The objective of the program is to get those date-time stamped price values into a text file or Excel spreadsheet and I would imagine this can either be done "tick-by-tick" whilst the code is running, or can be accumulated by the program whilst it is running and then gets dumped all in one go when the position is closed.

My problem is that according to the MQL4 book, only 1 EA can be running on a client at a time.  To me, this means that having a program that constantly checks over and over to look for new positions that are open or closed cannot be run as an EA every tick as the client will already be subscribed to a third party EA via the signals tab.  If I run the program as a script my understanding is that it only runs once and so it wont really be repeatedly checking for new positions.

I wonder if the solution involves a script with some kind of loop so that the code runs every second (or whatever), and checks for changes in currently open positions and also stores/posts any data to the log files for any positions that are open.

Would it be possible for any experienced MQL4 coders to comment on the above and perhaps offer any pointers or advice so that I start off on the right lines?  I am a complete rookie and know only what I have read/learnt from the internet over the last few days so please go easy on me!

In addition to the above, how much should I expect to pay if I wanted to commission an experienced MQL4 coder to help me develop programs to achieve parts A and B above?

Kind regards and thank you for any assistance that can be provided.  As the saying goes - "there's nothing more dangerous than a little bit of knowledge"!

Paul 

 

My problem is that according to the MQL4 book, only 1 EA can be running on a client at a time. 

 Not true, you can only have 1 EA running per open chart.

 
GumRai:

 Not true, you can only have 1 EA running per open chart.

Thank you for your response GumRai.  How do the EAs that are running on charts compare to the EA that I am subscribed to?  Does it mean that if I am receiving a signal via the Tools ---> Options (Signals Tab) then I have to open a chart and attach an EA to it for every possible currency pair for which the EA signal I am receiving could open a trade?   I hope my question makes sense!

Thank you again for your response.

 

Paul 

 
Porky2015: My problem is that according to the MQL4 book, only 1 EA can be running on a client at a time.
GumRai: Not true, you can only have 1 EA running per open chart.
So you open a second chart with the same pair, TF.
 
The "one at a time" that you are talking about, Porky, is one signal per account.  Your thoughts on scripts are correct, they are designed to be run once, and then quit.  If you want that script to run again, you have to tell it to run again.
 
JD4:
The "one at a time" that you are talking about, Porky, is one signal per account.  Your thoughts on scripts are correct, they are designed to be run once, and then quit.  If you want that script to run again, you have to tell it to run again.

Thanks JD4.  So does that mean I should write a script that runs in an infinite loop to do "part A" - i.e. a script that loops over and over to check whether any orders have been opened, closed, cancelled, etc, and if a trade is opened it attaches an EA to the chart which has an order open, and that EA runs an records ticks to a CSV file until the script tells it to unload? :)

Thank you again for your help! 

 

No, infinite loops are usually bad ideas.  Write an EA, they are designed to be "active" all the time.  Code it to read your order states you want to monitor.  I am not sure if you can write an EA to open a script when certain conditions are met or not though.  It seems like a bunch of coding, but I supposed, provided you can open a script from an EA, that you could code your overwatch EA to open scripts under certain conditions, and then if the script is directed to attach EAs to charts, to do that.


A simpler thought on this is why not just write an EA that does all the things you want in one, and attach it to the chart or charts and leave it on them?  Code your EA to record only if those conditions are met.  But as far as the ticks, MT doesn't use real ticks, according to posts I have seen.  The lowest they use is the data from the minute TF and calculate everything else from that.  I have tried to find the post where I outline my theory on how they do it, but did not find it yet.

Edit:  I found the post (https://www.mql5.com/en/forum/156166) where I proposed my theory, keep in mind that this is only a guess.  I do not know specifically how MQ calculates the tick values.

 
JD4:

No, infinite loops are usually bad ideas.  Write an EA, they are designed to be "active" all the time.  Code it to read your order states you want to monitor.  I am not sure if you can write an EA to open a script when certain conditions are met or not though.  It seems like a bunch of coding, but I supposed, provided you can open a script from an EA, that you could code your overwatch EA to open scripts under certain conditions, and then if the script is directed to attach EAs to charts, to do that.


A simpler thought on this is why not just write an EA that does all the things you want in one, and attach it to the chart or charts and leave it on them?  Code your EA to record only if those conditions are met.  But as far as the ticks, MT doesn't use real ticks, according to posts I have seen.  The lowest they use is the data from the minute TF and calculate everything else from that.  I have tried to find the post where I outline my theory on how they do it, but did not find it yet.

Thanks JD4.  I think Im "almost there".  Regarding the overwatch EA (as you put it) - I am struggling to understand how that fits in with MT4.  Must an EA must always be attached to a chart?  So would that mean my "overwatch" EA is just attached to any random chart just as a place to run?  If I have one or more charts open with EA's attached to them, does this conflict in any way with receiving signals via the Tools ---> Options ---> Signals tab?

Thanks for your patience! 

 
Porky2015:

Thanks JD4.  I think Im "almost there".  Regarding the overwatch EA (as you put it) - I am struggling to understand how that fits in with MT4.  Must an EA must always be attached to a chart?  So would that mean my "overwatch" EA is just attached to any random chart just as a place to run?  If I have one or more charts open with EA's attached to them, does this conflict in any way with receiving signals via the Tools ---> Options ---> Signals tab?

Thanks for your patience! 

For an EA to function, from my understanding, it does have to be attached to a chart.  I would think that the best place would be the chart for the code pair it is supposed to be working with.  As far as signals go, those are basically copied trades from the signal source.  I do not know if they would interfere with your EA(s) or not.  I am still learning to code MQL myself, and am far from an expert on it.  All I have down so far is the general ideas on most of the stuff.

Also, after going back and re-reading your OP, I noticed you are (or were) reading from both MQL 4 and 5.  You need to be careful with this, because MT4 cannot use EAs built for MT5 (which uses the MQL5 language).  There is a similarity between the 2 since MQ updated MQL4, but you need to be sure you are using MQL4 code when building your MT4 EA.  The same goes for MT5 using MQL4, you can't do it.  The code needs to be MQL5.

 
JD4:

For an EA to function, from my understanding, it does have to be attached to a chart.  I would think that the best place would be the chart for the code pair it is supposed to be working with.  As far as signals go, those are basically copied trades from the signal source.  I do not know if they would interfere with your EA(s) or not.  I am still learning to code MQL myself, and am far from an expert on it.  All I have down so far is the general ideas on most of the stuff.

Also, after going back and re-reading your OP, I noticed you are (or were) reading from both MQL 4 and 5.  You need to be careful with this, because MT4 cannot use EAs built for MT5 (which uses the MQL5 language).  There is a similarity between the 2 since MQ updated MQL4, but you need to be sure you are using MQL4 code when building your MT4 EA.  The same goes for MT5 using MQL4, you can't do it.  The code needs to be MQL5.

Cool, cheers for the warning JD4.  Thanks to everyones help on here, I think I have enough now to get myself started, and now I just need to "get my hands dirty" with some code and see how it goes.  The plan is to do lots and lots of coding using demo accounts and see where it leads me.  Thank you again for all of your advice! :)
 
Porky2015:
Cool, cheers for the warning JD4.  Thanks to everyones help on here, I think I have enough now to get myself started, and now I just need to "get my hands dirty" with some code and see how it goes.  The plan is to do lots and lots of coding using demo accounts and see where it leads me.  Thank you again for all of your advice! :)
Welcome, and good luck.
Reason: