AlgoTraderAlgoTrader Documentation

Appendix F. Example Strategy "Random"

The Strategy is a simple example that places random orders at regular intervals. The Random strategy is used for the AlgoTrader HTML5 Demo.

The Strategy sends a BUY order when shorter moving average (e.g. 10-days) crosses above the longer moving average (e.g. 20-days) and it sends a SELL order when shorter moving average crosses below the longer moving average.

The main artifacts needed for the Implementation of a new Strategy are described in chapter Chapter 5, Strategy Development.

The Random Strategy consist of the following artifacts:

/src/main/java/ch/algotrader/strategy/random/RandomService.java

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

/src/main/java/ch/algotrader/strategy/random/RandomConfig.java

Contains all strategy configuration items

/src/main/resources/module-random.epl

Esper Module containing statements to place and cancel orders as well as update subscriptions once a day.

/src/main/resources/conf-random.properties

Contains parameters used by the strategy (e.g. positionMax and orderMax)

/src/main/resources/META-INF/esper-random.cfg.xml

Contains variables (i.e. placeOrderInterval and cancelOrderInterval)

/src/main/resources/META-INF/applicationContext-client-random.xml

Contains the Spring Bean definitions for randomConfigParams, randomConfig, randomEngine, randomService.

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

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/random/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