AlgoTraderAlgoTrader Documentation

Appendix A. Example Strategy "BreakOut"

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.


The main artifacts needed for the Implementation of a new Strategy are described in chapter Chapter 5, 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 Chapter 4, Starting AlgoTrader.

To setup the strategy for back testing and live trading on a development workstation please execute the following steps:

To start the strategy in live trading mode on a development workstation please execute the following steps:

Initialize the database

load the db-samples script into the MySql database: /algotrader-core/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

Start the Strategy

invoke the Eclipse Launch Configuration: EmbeddedStarter-breakOut

To start the strategy in live trading mode on a productive server please execute the following steps:

Copy docker compose file

Copy the following file to the server and make changes as needed:

https://gitlab.algotrader.ch/main/examples/blob/master/breakOut/docker-compose.yml

Run docker compose

Invoke the following command inside the directory where the docker-compose.yml file is located:

docker-compose up -d