AlgoTraderAlgoTrader Documentation
The purpose of this Strategy is to demonstrate capabilities of AlgoTrader. Do not use it with a Live Trading Account and real Money! The strategy might lead to large losses. Even when modifying or extending the Strategy use caution before trading it Live.
The Strategy trades the EUR.USD FX Market and is based on a simple Breakout Indicator.
The Strategy opens a long (short) position when the current price exceeds (falls below) the maximum (minimum) of the last n bars. After a new position is opened, a profit target price is set as well as a stop loss. If either profit target or stop is reached, the position is closed. If neither stop nor profit target is reached until the end of n-bars, the position is closed.
Positions are sized based on a defined leverage and the current Net Liquidation Value. All Orders are placed as Market Orders. The initial account size is EUR 1'000'000.
The following 5-min bar chart gives an example of the BreakOut strategy. At 10:20 an aggregation of the last 5 bars between 09:55 and 10:20 is created, based on which the upper limit at 1113.85 and the lower limit at 1110.53 are calculated. At 10:22:37 the upper limit is crossed for the first time and a long position is entered and both a profit target at 1116.40 and a stop loss at 1111.49 are set automatically. At 10:31:52 the profit target is reached and the position is automatically closed.
This example strategy is a good example of combining a bar based strategy with tick-by-tick based actions. The creation of the upper and lower limits are based on the five 5-min bars but the opening and closing of the position takes place as soon as the limits are reached without waiting for the current bar to finish. This is one of the unique features of AlgoTrader that distinguishes it form other trading platforms that operate exclusively based on bars.
The main artifacts needed for the Implementation of a new Strategy are described in Chapter 4, Strategy Development.
The following list will give an overview of the specific artifacts implemented by the BreakOut Strategy (Note: Most of the functionality is documented via Javadoc or Esper comments):
/src/main/java/ch/algotrader/strategy/breakOut/BreakOutService.java
The strategy service class providing the main
entry
method invoked by the Esper
ENTRY_LONG
and ENTRY_SHORT
statements:
/src/main/java/ch/algotrader/strategy/breakOut/BreakOutConfig.java
Contains all strategy configuration items
/src/main/resources/module-breakOut.epl
Esper Module containing all statements for this strategy:
INSERT_INTO_BAR
: Creates High/Low
Bars
INSERT_INTO_BOUND
: Calculates minimum and
maximum of last n bars
ON_BOUND_SET_TRIGGERS
: sets the
upperTrigger
and
lowerTrigger
based on the minimum and
maximum of the last n bars
ENTRY_LONG
/
ENTRY_SHORT
: open position if last tick is
higher (lower) than previous n bars.
CLOSE_LONG_POSITION
/
CLOSE_SHORT_POSITION
: Close position if
last tick is higher (lower) than target or lower (lower) than
stop
CLOSE_OPEN_POSITION
: Close position if
neither target nor stop are reached before the end of
n-bars
/src/main/resources/breakOut-default.properties
Contains default parameters used by the strategy (e.g.
lengthOfBar
and
numberOfBars
)
/src/main/resources/META-INF/esper-breakOut.cfg.xml
Contains event-types definitions (i.e.
CurrentValue
), variables (e.g.
lengthOfBar
and
numberOfBars
) .
/src/main/resources/META-INF/applicationContext-client-breakOut.xml
Contains the Spring Bean definitions for
breakOutConfigParams
,
breakOutConfig
,
breakOutEngine
,
breakOutService
.
/src/main/resources/db/mysql/mysql-breakout.sql
Contains the MySQL database records. Needs to be imported into the database before running the strategy with the MySQL database.
To start the Strategy please see the explanations in Chapter 3, Starting AlgoTrader.
To setup the strategy for back testing and live trading on a development workstation please execute the following steps:
Perform a Git clone from the command line:
git clone https://gitlab.algotrader.ch/general/examples.git
Import the projects breakOut
into Eclipse via
File / Import / Maven / Existing Maven Projects:
download file:
eurusd-1min-20111218-20130121.zip
to:
breakOut/files/tickdata/eurusd-1min-20111218-20130121/EURUSD.csv
You can also import this tick data csv file into InfluxDB through the historical data manager (see Section 10.4, “Historical Data Manager” Historical Data Import) and run simulations based on the Influx data.
launch the Eclipse Run Configuration:
SimulationStarter-simulate-breakOut
To start the strategy in live trading mode on a development workstation please execute the following steps:
load the db-samples script into the MySQL database:
/algotrader-conf/src/main/resources/db-samples/mysql/mysql-data.sql
load the strategy specific script into the MySQL database:
/breakOut/src/main/resources/db/mysql/mysql-data.sql
invoke the Eclipse Run Configuration:
EmbeddedStarter-breakOut
To start the strategy in live trading mode on a productive server please execute the following steps:
Copy the following file to the server and make changes as needed:
https://gitlab.algotrader.ch/general/examples/blob/master/breakOut/docker-compose.yml
Invoke the following command inside the directory where the
docker-compose.yml
file is located:
docker-compose up -d
Prior to starting the strategy for the very first time please start the
AlgoTrader server by itself by executing the following command inside
/bootstrap/launch
. this will load the MySQL sample
data
docker-compose up -d mysql ibgateway algotrader