If for some reason you want pass values (like ask or bid) and receive answer (like sell or buy) from Forex Metatrader 4 to PHP or any other script language, there are two approaches:

  1. Call web server script (describe here)
  2. Execute command line script

Calling web server script, each time tick occurs might run out of free web server slots or even worse - lead out of free TCP ports in heavy testing situations, like strategy testing. Another approach, less resource intensive - to pass values to PHP and receive answer back to Forex Metatrader 4 expert is by calling external script using CLI. The only thing you have to aware is growing number of connection to MySQL (if you are using such).

Both methods work much slower as native MQL4 code. This might be an issue only while testing experts. In real trading I have not observe it as a problem (execution time is about 10 .. 50ms), other parameters like "slippage" during sharp market movements might provide even bigger headache.

How it works?

It is just an external library (DLL) allows your Forex Metatrader 4 expert communicate to PHP (or any other scripting language). So, if you are looking for expert or even Holy Grail - it is not here, at least not now :)

metatrader, mql4, php Future adjustments should be done in file fxphp.mq4

How to install

  1. Open Metatrader folder (ex: c:\Program Files\Alpari)
  2. Extract content of archive into folder "experts"
  3. fxphp.mq4 to experts
    fxphp.dll to experts/libraries;
    fxphp.mqh to experts/include;

  4. Adjust metatrader properties, allowing to run external DLL
  5. metatrader, dll
  6. From Naviagator view drag and drop expert to chart
  7. metatrader, navigator, experts

Most probably you will have to adjust path to PHP CLI (and PHP itself, if not yet done) and path to PHP script (callback.php). In my case path to PHP is set as system path, and PHP script located d://wamp//www//fx//callback.php.

Once it done and expert compiled, in Expert console you will get following messages. It is a ping back from PHP script

2012.03.20 02:05:21 fxphp EURUSD,M30: 2012.03.20 02:05:21;EURUSD;1.32293000;1.32306000
metatrader, experts, console

If something went wrong, please check FAQ section or use discussion bellow.

blog comments powered by Disqus
If you found this useful, please feel free to make a donation