AlgoTraderAlgoTrader Documentation

Appendix B. Example Strategy "Box"

The Strategy trades the EUR.USD FX Market and is based on the Stairstep Breakouts (SSBO) Indicator that is presented on by forexhard.

The Trading Idea behind the Strategy is the following: Markets will often stay within a trading range for a considerable amount of time before they break-out in either direction. The following Chart shows some examples of trading ranges.

After a break-out markets might return back into the trading range but will eventually make a major move in one direction.

According to the defined settings, the Strategy looks for a trading range with a minimum length in Minutes (e.g. 90 Minutes) and a maximum width in Pips (e.g. 30 Pips). The chart below displays a typical trading range in dark blue color.

As soon as trading range has been built according to these parameters, the Strategy waits for the first break-out to happen. The strategy enters the market in the direction of the breakout as soon as a small margin called buffer (dashed red line, e.g. 5 Pips) has been crossed. In the example above, this happened at 10:48.

The Strategy will set a stop at the opposite side of the box (e.g. 1.3618 = 39 Pips) and a target with the same distance (e.g. 1.3544 = 39 Pips).

If the target is reached, the Strategy resets itself and waits for a new Box to build itself.

If the Position gets stopped out (at the opposite side of the Box), The Strategy waits for the next break-out to happen (on the same Box) and enters the market again after the buffer-line has been crossed. This time the size of the position is doubled in order to cover the losses of the first entry, in case the target is reached this time around. Position size is doubled up to a defined maximum. Because of this doubling the system can be categorized as a Martingale Strategy (see Martingale Betting System).

The following State Chart Diagram depicts the different states the Strategy will pass through:

The default setting of the Strategy will go up to level 5 which will result in a position size of 16 times the original size. So the individual sizes on the different levels will be: 1, 2, 4, 8 & 16. Each successful series will therefor present a profit of 1 unit. Very often series will be successful on a level that is below the maximum level (e.g. below level 5). However if the Strategy has a loosing set, which will be terminated at the maximum level (e.g. at level 5), there will be a loss of 16 times the original position size.

The Strategy will often have multiple successful series in a row before having one major draw down. A typical performance chart will therefore look like this:

To prevent having open positions over the weekend the Strategy does not create any new boxes after a defined time on Friday (e.g. 4PM). Also, it will terminate a potential ongoing series at a defined time on Friday (e.g. 10PM)

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 Box Strategy. Most of the functionality is documented via Javadoc or Esper comments:


The strategy service class providing the main methods invoked by different Esper statements.


Contains all strategy configuration items


A POJO class representing all properties of a Box (e.g. top, bottom, startDateTime and endDateTime)


A Java Enum representing the different States the Strategy can pass through (INIT, CREATED, LONG, SHORT, FLAT)


Esper Module containing statements for capturing market data, creating variables and creating Boxes. In Live Trading, these statements will be deployed before the pre feeding.


Esper Module containing statements that invoke the business actions on the BoxService (entry, takeProfit, closePosition, reverse and terminateSeries). In Live Trading these statements will be deployed after pre-feeding is finished.


Contains parameters used by the strategy (e.g. boxLength and boxRange)


Contains event-types definitions (i.e. CurrentValue), imports (i.e. Box and State), variables (e.g. boxLength and boxRange)


Contains the Spring Bean definitions for boxConfigParams, boxConfig,boxEngine, boxService.


Contains the MySQL database records. Needs to be imported into the database before running the strategy with the MySQL database.


HTML5 and JavaScript files needed for the strategy custom web UI

To start the Strategy please see the explanations in Chapter 3, Starting AlgoTrader.

The Box strategy is equipped with an HTML5 custom widget that displays current metrics like State, Units, Upper Target, etc. The custom widget also contains a button to terminate the current series


It might be necessary to fully reload the browser on first startup to show the custom widget using Ctrl + Shift + R.

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

Git clone

Perform a Git clone from the command line:

git clone

Import the projects box into Eclipse via File / Import / Maven / Existing Maven Projects:

Deploy Bar Data File

download file:

and unpack to:


You can also import this bar 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.

Start the Simulation

launch the Eclipse Run Configuration: SimulationStarter-simulate-box

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-conf/src/main/resources/db-samples/mysql/mysql-data.sql

load the strategy specific script into the MySQL database: /box/src/main/resources/db/mysql/mysql-data.sql

Start the Strategy

invoke the Eclipse Run Configuration: EmbeddedStarter-box

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:

Run docker compose

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