Skip to content

Commit

Permalink
simplify setup in MetaTrader by pre-compiling MQL4 files in the maven…
Browse files Browse the repository at this point in the history
… build
  • Loading branch information
rbi committed Dec 5, 2016
1 parent cde8cce commit 2ea73f6
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Trading4j
Trading4j is a library that allows to write automated expert advisors for Forex trading. The library promotes writing code that is reusable across different expert advisors by clearly separating between different aspects of expert advisor programming. Examples for these aspects are strategies, indicators, money management and order filtering.

Expert advisors written with trading4j can place orders through the well known trading terminal <b>MetaTrader</b>. Therefore a wide range of brokers is supported while still having all the benefits of programming on the Java platform.
Expert advisors written with trading4j can place orders through the well known trading terminal *MetaTrader*. Therefore a wide range of brokers is supported while still having all the benefits of programming on the Java platform.

# Getting Started
To get started with programming with trading4j take a look at the <b>examples</b> directory. The example contains a server that serves an exemplary expert advisor.
To get started with programming with trading4j take a look at the *examples* directory. The example contains a server that serves an exemplary expert advisor.

The directory <b>client-metatrader</b> contains a MetaTrader compatible expert advisor. This expert advisor will connect to the server created with trading4j to delegate the trading decisions. To install it, build the Maven project <b>client-metatrader</b>. At the moment you need a C/Windows cross-compiler named <b>i686-w64-mingw32-gcc</b>. In Ubuntu 16.04 you can get this by installing the package <b>mingw-w64</b>. After the build you get a ZIP bundle in the target folder. Unzip it in the MetaTrader directory. Open the MetaEditor and compile the newly installed expert advisor <b>Trading4jRemoteExpertAdvisor.mq4</b>. After that, the expert advisor is available in MetaTrader terminal, e.g. for backtesting or live trading.
The directory *client-metatrader* contains a MetaTrader compatible expert advisor. This expert advisor will connect to the server created with trading4j to delegate the trading decisions. To install it, enable building the Maven project *client-metatrader* by activating the Maven Profile *client-metatrader*. At the moment you need a C/Windows cross-compiler named *i686-w64-mingw32-gcc*. In Ubuntu 16.04 you can get this by installing the package *mingw-w64*. You also need *wine* and a *MetaTrader* installation. You need to set the Maven property *metaeditor.executable* (e.g. in your *settings.xml*) to point to the *metaeditor.exe* executable. A working Maven comand line could look as the following: `mvn -Pclient-metatrader -Dmetaeditor.executable="~/.wine/Program Files (x86)/MetaTrader 4/metaeditor.exe" install`.

After the build you get a ZIP bundle in the target folder. Unzip it in the MetaTrader directory. The expert advisor should now be available in MetaTrader terminal, e.g. for backtesting or live trading.

In future a pre-compiled version of the client is planned to simplify the setup of the client for MetaTrader.

# License
Trading4j can be used under the terms of the <b>GNU General Public License Version 3</b>.
Trading4j can be used under the terms of the **GNU General Public License Version 3**.
24 changes: 24 additions & 0 deletions client-metatrader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<artifactId>client-metatrader</artifactId>
<packaging>pom</packaging>

<properties>
<!-- Override this in your profile with the actual path to meta editor. -->
<metaeditor.executable>metaeditor.exe</metaeditor.executable>
</properties>

<name>Trading4j - client for MetaTrader</name>
<description>Contains a client for MetaTrader that allows accessing trading algorithms written using Trading4j over the network.</description>

Expand Down Expand Up @@ -54,6 +59,25 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>compile-mql4</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${project.basedir}/src/main/build/compile-mql4.sh</executable>
<arguments>
<argument>${metaeditor.executable}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client-metatrader/src/main/assembly/metatrader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.basedir}/src/main/mq4</directory>
<directory>${project.build.directory}/mq4</directory>
<outputDirectory>MQL4/</outputDirectory>
</fileSet>
</fileSets>
Expand Down
17 changes: 17 additions & 0 deletions client-metatrader/src/main/build/compile-mql4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
METAEDITOR="$1"

BASE_DIR="`dirname $0`/../../.."
TARGET="$BASE_DIR/target"
MQL_SOURCE="$BASE_DIR/src/main/mq4"
MQL_BUILD="$TARGET/mq4"

echo compiling mq4 files to "$MQL_BUILD"

mkdir $TARGET
rm -r $MQL_BUILD
cp -r $MQL_SOURCE $TARGET
wine "$METAEDITOR" /compile:"`winepath -w $MQL_BUILD`"

# return status of metaeditor seams to be allways non-zero, at least when executed with wine
exit 0
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<module>core</module>
<module>server</module>
<module>examples</module>
<module>client-metatrader</module>
</modules>

<properties>
Expand Down Expand Up @@ -198,6 +197,11 @@
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand Down Expand Up @@ -229,4 +233,12 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>client-metatrader</id>
<modules>
<module>client-metatrader</module>
</modules>
</profile>
</profiles>
</project>

0 comments on commit 2ea73f6

Please sign in to comment.