Custom Event: Call from EA1 to EA2

 

Let's say in the same MT4 terminal there is one EA running on a EURUSD chart and one EA running on a GBPUSD chart.


If there is a new tick for EURUSD, the code inside of the OnTick() function of the EURUSD EA will be executed.

Under certain conditions I want it to make a call to the GBPUSD-EA, so code inside the GBPUSD-EA can be executed before a new tick for GBPUSD happens.

 

Is this possible using EventChartCustom() function? How can I do this?

By the way, I do not want a simple EventSetMillisecondTimer() "solution" because even if the timer is set to 1ms, code would only be executed every 15ms using EventSetMillisecondTimer(1).


Many thanks in advance!

 

You are asking a question and answering it.

How to use EventChartCustom() ? read the documentation and write it in your code.

 
jan100:

Under certain conditions I want it to make a call to the GBPUSD-EA, so code inside the GBPUSD-EA can be executed before a new tick for GBPUSD happens.

Is this possible using EventChartCustom() function? How can I do this?

Yes.

 

Come up with an id for your chart event. Both EA's will need to know this.

e.g.

#define EVENT_ID 12345

 

In the EURUSD EA, send your custom chart event when your conditions are met.

You will need to know the ChartID of the GBPUSD chart, else broadcast the event to every chart in the terminal.

e.g.

EventChartCustom(CHART_ID, EVENT_ID, 00NULL);

 

In the GBPUSD EA, have a section in the OnChartEvent to react to the chart event.

e.g.

if(id == CHARTEVENT_CUSTOM + EVENT_ID)

 

That's it! 

 

Edit : Alain beat me to it 

 
honest_knave:

Yes.

...

Edit : Alain beat me to it 

Yeah but you are nicer than me, giving all these details.
 
Thanks a lot!
 

By the way, is there also a way to call an MT4 EA from an external program?

 

For example, if something happens inside an external program, the code inside the MT4 EA should be executed immediately. 

 
jan100:

By the way, is there also a way to call an MT4 EA from an external program?

 

For example, if something happens inside an external program, the code inside the MT4 EA should be executed immediately. 

You may trigger a tick event on the specific chart from the external program. The program needs to know the chart window handle to send the message to, so you need to pass the handle to the application first.
 
Ovo Cz:
You may trigger a tick event on the specific chart from the external program. The program needs to know the chart window handle to send the message to, so you need to pass the handle to the application first.

Thanks a lot!

Unfortunately I have no idea how to do that. 

 
Or you can create a semaphore (that way you don't need to know the target handle or anything about the target at all). Coupled with a timer events in the target EA,  you can have event processing without raising external event

But in any case - you will have to run them on the same computer which limits the whole thing a lot
 
Thanks, but not a real "soltution" because code inside EventSetMillisecondTimer(1) is only executed about every 15.6ms, so I think it has to be without the use of MT4 timer.
 
jan100:
Thanks, but not a real "soltution" because code inside EventSetMillisecondTimer(1) is only executed about every 15.6ms, so I think it has to be without the use of MT4 timer.
Sorry, but what difference does the 1 to nnn ms make?

You are using mql for start - not low level parallel computing on Cray® XC50™. If you are trying to HFT then you shall have to migrate to something completely different (starting from replacing your computer with a COMPUTER and the place you work for an office that is 100 feet from your broker and, in the end, replacing the platform and coding environment used ...). Otherwise, the difference means completely nothing in real time mt usage and trading
Reason: