The Gateway to Algorithmic and Automated Trading

Using Order Book Data to Improve Automated Model Performance

Published in Automated Trader Magazine Issue 06 July 2007

Automated traders now have access to unprecedented levels of market data. Thom Hartle, Director of Marketing, CQG, conducts a theoretical comparison between two trading systems to explore how order book data can be leveraged for optimal trade performance.

Thom Hartle

Thom Hartle

The advent of electronic trading platforms for futures and cash markets has created greater market transparency. The availability of this level of market information has led to innovative ways of tracking the actions of traders within an exchange's electronic order book. Historically, traders only had the last price as the first input to an automated trading model. Today, we can ascertain whether the last price was generated by a trade at the bid price (selling) or a trade at the ask price (buying). The question is: can that information be an additional filter as an aid to improving trade performance?

This article compares the effectiveness of two trading systems. One system uses a price-based oscillator for the entry signal generator; the second uses an executed volume-based oscillator for the entry signal generator. The core market situation we shall explore is as follows: the market trend direction is identified, then an oscillator is employed to initialise entry signals following an indication that a countertrend movement is complete and the price action is moving in the direction of the trend. The market tested is the E-mini S&P futures.

TradeFlow Bars

As well as outlining the trading model, it's necessary to explain some of the basic functions of the charting format (CQG's TradeFlow) that exploits the market transparency described and is used in this article for the purposes of illustration. The two elements (trades at the ask and trades at the bid) of the TradeFlow bar are used as the basis for an oscillator for the entry signals for one system. The basic TradeFlow bar uses the best bid as the low and the best ask price as the high for the bar. For example, if the E-mini S&P futures contract was 1515.75 bid and offered at 1516.00, the low of the TradeFlow bar is 1515.75 and the high is 1516.00.

The TradeFlow bar is colour-coded on a percentage basis by the amount of volume executed at the ask price. If 400 contracts traded at the 1516.00 offer and 100 contracts traded at the 1515.75 bid, then the bar would be 80 per cent green and 20 per cent red. The degree of colour brightness and the width of the bar are based on the current bar's executed volume relative to the range of volume levels in a predetermined look back period. The higher the current bar's traded volume relative to the range of reported traded volumes, the brighter the colour and the wider the TradeFlow bar. Finally, time is not a factor in the TradeFlow bar building.

Figure 1: The basic TradeFlow bar's high is the ask price and the low is the bid price of the inside market. The bar is colour-coded to reflect the percentage of volume traded at the ask (green) versus trades into the bid (red). The width and colour brightness is based on relative volume of trades for one TradeFlow bar compared to a look back period. The openhigh- low-close bar chart does not indicate any traded information other than last price.

There are a number of key bits of information gleaned from the TradeFlow bars. Wide andbrightly-coloured TradeFlow bars denote high activity price action. Thin and darkly coloured TradeFlow bars indicate low activity price action. In fact, a TradeFlow bar can have no volume (there is a bid and ask price, but no trades) and the bar is gray.

The colour-coding indicates on which side of the market traders were most active. An all-red TradeFlow bar indicates that traders hit bids and did not lift any offers. An all-green TradeFlow bar indicates that traders lifted offers and did not hit any bids. A mixture of green and red signifies that traders were on both sides of the market and the breakdown of the colour is a percentage of the buying and selling.

Figure 1 is an example of a series of TradeFlow bars compared to classic one-minute open-high-low-close bars to illustrate the information available to the trader using TradeFlow charts. The basic price bar tells you the last price, but not who the aggressor was, i.e. the buyer or the seller to generate the last price.

The left-hand side of the TradeFlow chart in Figure 1 shows six nearly all-green TradeFlow bars from 1537.50 up to the high of 1538.75 indicating aggressive buying. The top bar is almost all red, indicating traders came in and aggressively hit the 1538.50 bid. From there, the inside market falls and traders continued to hit bids.

At the bottom, the TradeFlow bars between 1536.50 bid and 1536.75 ask are nearly all green as traders lifted offers. None of this information is available from the regular price bars. You would not have any reason to think the 1538.75 price might be a shortterm top in the price bar chart.

For this article, a three-tick range aggregation level is used. All TradeFlow bars are three ticks in price range. As long as the inside market does not move outside of the current three-tick range for the current TradeFlow bar, the bar continues to build based on any traded volume. This aggregation feature compresses the price action in a similar fashion to the classic point & figure charting style.

Comparing the Trading Systems

In our market scenario, the two systems identify the trend as either up or down, and then an oscillator is the basis to indicate that a countertrend movement is underway or complete. When the latter indication occurs, a trade is entered in the direction of the market trend. The definition of the trend direction is the 100-bar simple moving average is shifting higher or lower based on the one-bar difference. Trade System 1 uses the Moving Average Divergence Convergence (MACD) study as the oscillator for gauging the countertrend movement. The classic MACD study is the difference between the 26- and 13-bar exponential moving averages; a nine-bar exponential moving average is used as a signal line.

Here, only one element of the MACD study is used: the differences between the 26-bar and 13-bar exponential moving averages which are plotted as histogram bars in Figure 2.

If the MACD histogram bars are rising, then the difference between the 13-bar and the 26-bar exponential moving averages is climbing. If the MACD histogram bars are in positive territory, then the 13-bar is above the 26-bar exponential moving average. Moreover, if the MACD histogram bars are in negative territory, then the 13-bar is below the 26- bar exponential moving average. This situation is the precursor to the buy signal.

The buy signal

If the one-bar difference of the 100-bar simple moving average is positive, the trend is up. If the MACD histogram bars are in negative territory and the one-bar difference is less negative than the previous one-bar difference (indicating momentum is shifting upward), then buy at the opening of the next TradeFlow bar (Figure 2).

A 1.50 point target is the profit objective for the trade. For risk management, the stop loss used is a two-tick break below the low of the entry bar for long signals and a two-tick rise above the high of the entry bar for short positions. Remember that the TradeFlow bar can only be three ticks' range before a new TradeFlow bar is generated. Therefore, once in a trade, the maximum loss is five ticks, but the stop could be as close as just two ticks.

In addition, trades are not allowed in the first five minutes of the session (the session is 08:30-15:15 Central Time) and any open trades are exited five minutes before the close of the session. Short sell signals use the opposite criteria.

Figure 2: The MHist study is the difference between the 13-bar and the 26-bar exponential moving averages of the price (MACD). During an uptrend (signaled by the rising 100-bar SMA), the buy signal is when the MACD histogram bar climbs one bar while in negative territory and there is no current trade.

Some comments about Figure 2 are in order. First, the double arrows mark the TradeFlow bars to the MACD histograms that qualify as the buy condition. The blue arrows on the TradeFlow bars mark the entry bar for the long signal, which is the opening of the next TradeFlow bar following the condition being met. We don't know the condition is met until the TradeFlow bar closes, which occurs when the three-tick range is violated and a new TradeFlow bar starts. The opening price of the new TradeFlow bar is the trade. The solid blue line indicates the entry price. The dotted blue line is the stop loss level and the X indicates the target price was hit. There were three successful trades in Figure 2. The core concept is to go long, following a pullback. In Figure 2, the first two trades fit this dynamic. The third trade is more of a buying into upward momentum trade. The conditions for the third trade are met on the same TradeFlow bar that met the exit rules of the second trade. An additional rule could be to only permit one signal per negative grouping of the MACD histograms during an uptrend. Figure 3 displays the performance of the trading system from the May 30 through June 5, 2007. Table 1 details the system statistics.

Figure 3: The equity line for the system using the MACD oscillator is hit hard initially, but recovers. Performance suffers when the market is moving counter to the 100-bar simple moving average.

The equity line in Figure 3 initially moves well into negative territory because the gap down in price on the opening pulls the moving average down and the systemissues sell signals, despite the price recovering from the early opening weakness. The sell signals were lagging the price peaks during the recovery and the stops were subsequently hit because the 1.50-point target was not being met. However, the equity line starts climbing once the price action moved above the rising moving average. The equity line then moves back and forth between positive and negative territory. The equity line tended to climb when the market was above the rising moving average. It appears that the standard MACD parameters worked best under these conditions as the market tended to hit the target and not the stop loss points.

Trade system 2: Volume-based oscillator

Trade System 2 uses the same definition for the trend, target, and risk management rules, but the oscillator uses elements of the aggregated three-tick range TradeFlow bars. Each TradeFlow bar includes the volume of trades at the ask price (buying) and the volume of trades at the bid price (selling). This information was the basis for a study, here called TradeFlow Cross, which is the source for the oscillator for the trading system.

Figure 4: TradeFlow bars use traded volume at the ask price and at the bid price. These two elements are the basis for the TradeFlow Cross study, which are the five-bar running sums of the traded volumes. The oscillator (middle pane) for the trading system is the difference between the two TFCross curve

Figure 4 shows the TradeFlow Cross study plotted in the bottom pane. The green line is the five-bar running sum of volume of contracts traded at the ask price (buy volume). The red line is the five-bar running sum of volume of contracts traded at the bid price (sell volume). The oscillator for the trading system is the difference between the buy volume and the sell volume lines. In Figure 4, the price is initially dropping and the sell volume line (red) is dominating the buy volume line (green). Then the market starts to climb and the buy volume line climbs above the sell volume line. As the market advances however, the buy volume line makes a lower peak than the first peak, indicating less trades going off at the ask price, and the market forms a short-term top.

The oscillator for Trade System 2 is displayed in the middle pane: TradeFlow Volume Up minus TradeFlow Volume Down (TFUmTFD). Arrows mark a turn up from negative territory by the oscillator and a turn down in positive territory.

The difference between the TFUmTFD oscillator and the MACD is that the MACD is measuring the last price with no insight into whether the last price was generated by a trader hitting the bid or lifting the offer. The last price could be higher than the previous price because the inside market climbed, however traders hit bids or sold into the higher bid to generate the last price. The TFUmTFD study is only measuring buying versus selling volume and is not checking whether the last trade was higher or lower than the previous trade. Figure 5 shows two trades over he same period as Figure 2, which had three trades.

Figure 5: The TFUmTFD study is the difference between the five-bar running sum of trades at the ask and the five-bar running sum of trades at the bid. When the histogram bars climb while in negative territory, the indication is there is a shift by traders towards buying relative to selling.

The first trade in Figure 5 is one TradeFlow bar late compared to the first trade in Figure 2. This occurred because there was only one negative TFUmTFD histogram bar during the congestion period and two are required with the second TFUmTFD histogram bar being less negative than the first. The third trade from Figure 2 did not occur in Figure 5 because the market was climbing with steady buying (the TFUmTFD study was positive) over the rest of the chart.

Superior performance

Figure 6 shows Trade System 2 using the TFUmTFD oscillator applied to the same test period as Figure 3 (May 30 through June 5, 2007). Table 2 details the performance statistics.

Figure 6 shows that despite the gap down in price during the initial portion of the test period, the sell signals tended to catch the peaks of a few rallies and netted out profits by hitting the downside target despite the climbing price action. This offset the losing short sell trades as the market recovered from the gap down opening.

Once the moving average turned up, led by the price action, the trading system (similar to the MACD oscillator signals) booked a number of winning trades. The trading system then tended to generate a sideways equity line similar to the MACD oscillator system.

Figure 6: The equity line for the system using the TradeFlow volume elements climbs steadily during the first half of the test period.

Comparing Tables 1 and 2, there is difference between the results from the two oscillators. Trade System 2, using executed volume for the oscillator, generated a net profit versus a loss for Trade System1. Trade System 2 did have nine more trades, but the percentage of winners was 47.52 per cent versus just 34.78 per cent.

Reality Check

Is it reasonable to compare two oscillators where one is built on the difference between two exponentially smoothed moving averages of the price and the other on the difference between the five-bar running sum of the traded bid and ask volumes? Figures 2 and 5 did show one set of similar trades. Calculating the correlation coefficient between the two oscillator raw outputs over the course of the test period showed a 0.52 correlation. The results of running a rolling 100-bar correlation between the two studies are displayed in Figure 7.

Figure 7 shows that the correlation between the two oscillators did at times run at high levels, having exceeded 0.80 a number of times. This makes sense in that trades consistently going off at the ask price or bid price should lead to the market trending, and the price-based oscillator should run in the same direction as the traded volumebased oscillator. On the other hand, the traded volume-based oscillator did use a five-bar running sum as the core calculation, and this small calculation window may have made the oscillator sensitive enough to be coincident with the end-points of countertrend moves. There was no optimisation of parameters for this example, just anecdotal experience to set targets and stops. These parameters could be optimised and then in- and outof- sample testing performed.

Figure 7: The rolling 100 bar window correlation coefficient of the MACD readings and the TFUmTFD study readings peaked above 0.80 indicating a high correlation at times.



Finally, trading systems designed to buy pullbacks in uptrends and sell rallies in downtrends suffer draw downs when the countertrend movement is either excessive or actually part of a trend reversal. An additional rule could be to allow only one entry signal per qualified crossover by the oscillator (i.e. one buy signal when the oscillator is in negative territory).

Electronically-traded markets have opened up new areas of research through greater market transparency. Automated trading can now utilise market information beyond just the last price. Besides knowing whether a trader hit a bid or lifted an offer to generate the last price, market data such as how the inside market was behaving, as well as order management by traders in the depth-of-market ladder, are now available as the basis for trading signals.