Can a Trading System Learn by Example?

If you’ve used chart indicators for a while you’ll probably agree that often they give conflicting messages. Sometimes one indicator suggests a buy, another says hold, while a different one is signalling a sell.

Can Trading Systems be Adaptive?

Can a trading system learn by example?
Can a trading system learn by example? © forexop

This gives rise to two questions:

1) How can different indicator signals be combined into one decision?

2) How can you use the outputs according to their reliability?

The good thing about chart indicators is that there’s feedback. From future prices you can measure how good any indicator was at any time. In other words, you can confirm whether a buy, sell or hold signal from an indicator was the right decision or not.

There are several kinds of algorithms that learn by example – these are known as machine learning and covers:

  • Neural nets
  • Genetic algorithms
  • Pattern matchers

Combining Inputs

Most auto trading systems rely on more than one indicator or system to make their trading decisions. The tricky question then arises as to how to use inputs from these different systems in a meaningful way.

Suppose I create a simple trading system and I use these conditions to indicate a buy signal:

Indicator 1: Momentum equal or above 100 (F1)
Indicator 2: MACD between 30 and 50 (F2)
Indicator 3:
RSI between 40 and 50 (F3)

Now suppose I find at one instant that Momentum=99.9, MACD=45, and RSI=45.

Indicator 1 is just outside of my hard limit. But indicator 2 and 3 indicate a strong buy. I therefore reject a buy signal at this instant. But was that the right decision or not?

Because I’ve put in hard limits, there is no flexibility in the interpretation of the inputs from the measurements. In this case, I may have wrongly rejected a good buy entry signal.

Worse, I could have accepted a buy signal or sell decision when the opposite would have been the correct choice.

Everyone knows that trading decisions are rarely black and white. It could have been the case that during a period, indicator 1 (momentum) had proven less reliable than the others. I could easily check this against real data. In this case, should I have accepted the signals from the other indicators and entered a buy side trade?

This highlights several problems with this: First, there is no way to account for relative importance of each indicator. One indicator may be more reliable than another – especially when it lies within a certain range or at different times.

Second, this method doesn’t handle conflicts very efficiently. For example what should I do when one input is just outside of the hard range, but the others are firmly within?

Thirdly, the logic for trading decisions has to be developed by “trial and error”.

The greater the number of indicators used the more complex this task becomes.

Interpreting Inputs Together

A better system is one that “weighs up” all of the inputs together. So what data analysis techniques are available to help with this problem?

One approach is machine learning. With this, I can do several useful things:

  • Weight each indicator input according to its reliability
  • Vary the importance of each outcome (buy, sell, hold) according to other inputs
  • Allow the system to modify itself based on feedback

For example, an artificial neural network – ANN uses three layers to make each decision. These are the Input-Hidden-Output layers.

The ANN – Artificial Neural Net

Let’s consider a simple example trading system. The goal of this system is to identify Bollinger squeezes and trade on the breakouts that often follow them. Sometimes these events are called volatility breakouts. An example of one such event is shown in Figure 1 below.

Figure 1: Classic Bollinger squeeze followed by a volatility breakout
Figure 1: Classic Bollinger squeeze followed by a volatility breakout © forexop

To identify these chart patterns I start by using the following thee indicators:

  • Bollinger bandwidth (F1)
  • Standard deviation (F2)
  • Slope of the moving average line (F3)

As short hand, I’ve labelled these F1, F2 and F3. These are the input layer.

The first thing I have to do is train my network with these indicators and with the data. To start with I examine a sample of these indicator values from various points along the EUR/USD M5 timeseries. What this training phase will do is examine some data points, and check how good each of the above indicators (F1, F2, & F3) was at identifying these chart events.

The network has to be trained with suitable examples. The most common method to do this is known as back propagation.

We then apply these to the ANN to decide on buy, sell or hold at appropriate points.

When choosing a set of indicators, it is important to select those with the strongest discriminatory value. This will normally involve a bit of experimentation and number crunching to find the optimal set for a given chart.

Figure 2: ANN input layers
Figure 2: ANN input layers © forexop

Applying the ANN to Identify Bollinger Squeezes

Once the network is trained, the next stage it to check the decision boundaries. These are where the network discriminates one case from another.

In other words, given inputs from the indicators, what action should I take: buy, sell or do nothing.

Let’s say at tick n, we have a set of outputs from the indicators. The outputs are fed into the input layer, and that goes through the hidden layer, and the result is made at the output layer.

Figure 3: Points #1 and #2
Figure 3: Points #1 and #2 © forexop
Figure 4: Points #3, #4 and #5
Figure 4: Points #3, #4 and #5 © forexop
Figure 5: Point #6, classifies as a sell
Figure 5: Point #6, classifies as a sell © forexop
Figure 6: Point #7, classifies as a buy
Figure 6: Point #7, classifies as a buy © forexop


Using this method we tested several scenarios over a ten year time frame using both GBP/USD and EUR/USD at the M5 (five minute) scale.

Training phase

The Bollinger squeeze patterns were identified by eye in the first phase. This was done using a separate part of the data series outside of the test frame. This formed the input data.

Decision phase

Once the input set was generated, the test run then applied the network on a different part of the time series to make real trading decisions.

The first chart shows the result on GBP/USD. The system made 640 trades with total profit of $50k.

Figure 7: Automated learning strategy GBP/USD M5 example. Total profit $50k.
Figure 7: Automated learning strategy GBP/USD M5 example. Total profit $50k. © forexop

The second chart shows the result on EUR/USD. The system made 568 trades with total profit of $28k.

Figure 8: Automated learning strategy EUR/USD M5 example. Total profit was $28k.
Figure 8: Automated learning strategy EUR/USD M5 example. Total profit was $28k. © forexop


The big challenge of using indicators is that of interpretation. The main problem is:

  • Which indicator is reliable and when
  • How do you make reliable trading decisions based on the indicator outputs

Artificial Neural Nets are systems that learn and adapt based on the data.


Price Action Trading

Definitive Guide

Price action trading with candlesticks gives a straightforward explanation of the subject by example. It includes data insights showing the performance of each candlestick strategy by market, and timeframe.

  1. Steve, thank you for this article. Very interesting to me as I am looking at building a neural net EA for a while now.
    What do you recommend is the highest number of indicators you can use with this technique? I want to combine the signals of about 10 indicators.

    • It can extend indefinitely the only limit is computation time. The inversion of the covariance matrix can be a bottleneck if you are planning on putting in a huge number of indicator outputs.

      But in my view more is not always better. Especially as I said above when you look at the redundancy issue that many indicators have. PCA reduction can come in useful and could drastically reduce the data set. With a massive set of inputs there could also be a problem with training and over-fitting of the data.

      As for the neural net idea yes that’s certainly a choice for this kind of learning algorithm. There’s also some overlap with the methods.

Leave a Reply