So you want to use Genetic algorithms to do Forex trading, eh?
Where should we start? I'm going to use the specifics of JGAP (since that is the platform I've picked for my development) but the concepts should work with any genetic structure.
Let's start at the very beginning: what exactly is the basis of what we are trying to implement? Is it the case that:
- we have a specific trading system or set of indicators that we think will do the trick when tweaked just so? In this case the goal is to evolve a system with optimal parameters.
- we don't really have a specific system in mind. We would then have a completely naive system, which starts from a large set of indicators and builds its own trading methods.
The first case, that of a specific trading system which is to be optimized, is the simpler case. Let's plan a Chromosome for a trivial trading system. Define the trading system Genes as:
- a Long position is entered when a shorter-duration moving average crosses above a longer-duration MA, AND
- RSI rises from below a certain threshold to above a certain threshold
- No short positions will be taken
- position is closed when a fixed number of pips are gained, OR
- position is closed when a fixed number of pips are lost from the maximum advancement of the position (a trailing stop)
Gene 1 implements the cross of moving averages. How many variables can we extract from that operation?
|
Component |
Variables |
| shorter moving average | bar length |
| type (simple, weighted, exponentially smoothed) | |
| longer moving average | bar length |
| type (simple, weighted, exponentially smoothed) |
Really, it seems as though this should be something that is evolved on on its own. For a system of sufficient complexity the combinatorial expolsion of possibilities means that it would take much longer to find an optimal solution for any single gene within the whole. So let's split this task out into a separate Chromosome.
Let's define the Moving Average Chromosome as having the four genes above.
| Indicator | variable | range |
|---|---|---|
| ShorterMA | bar length | 5-15 |
| Type | simple, weighted, Smoothed EMA | |
| LongerMA | bar length | 16-30 |
| type | simple, weighted, Smoothed EM |
Evolution of this should be tested by many runs through the Open Forex Platform backtesting framework.
But what is the fitness function? See The next post for that! :)