Using Order Book Data - CQG Thom Hartle Reprinted from the July 2007 issue of Automated Trader...

8
by Thom Hartle Reprinted from the July 2007 issue of Automated Trader Magazine Q3 2007 Using Order Book Data Improve Automated Model Performance TradeFlow Charts and Studies - Patent Pending TM TM www.automatedtrader.net

Transcript of Using Order Book Data - CQG Thom Hartle Reprinted from the July 2007 issue of Automated Trader...

Page 1: Using Order Book Data - CQG Thom Hartle Reprinted from the July 2007 issue of Automated Trader Magazine Q3 2007 Using Order Book Data Improve Automated Model Performance

by Thom Hartle

Reprinted from the July 2007 issue of Automated Trader Magazine

Q3 2007

Using Order Book Data

Improve Automated Model Performance

TradeFlow Charts and Studies - Patent PendingTMTM

www.automatedtrader.net

Page 2: Using Order Book Data - CQG Thom Hartle Reprinted from the July 2007 issue of Automated Trader Magazine Q3 2007 Using Order Book Data Improve Automated Model Performance

The advent of electronic trading platforms forfutures and cash markets has created greatermarket transparency. The availability of this

level of market information has led to innovative waysof tracking the actions of traders within an exchange’selectronic order book. Historically, traders only hadthe last price as the first input to an automatedtrading model. Today, we can ascertain whether thelast price was generated by a trade at the bid price(selling) or a trade at the ask price (buying). Thequestion is: can that information be an additionalfilter as an aid to improving trade performance?

This article compares the effectiveness of two tradingsystems. One system uses a price-based oscillator forthe entry signal generator; the second uses anexecuted volume-based oscillator for the entry signalgenerator. The core market situation we shall exploreis as follows: the market trend direction is identified,then an oscillator is employed to initialise entrysignals following an indication that a countertrendmovement is complete and the price action ismoving in the direction of the trend. The markettested is the E-mini S&P futures.

TradeFlow Bars

As well as outlining the trading model, it’snecessary to explain some of the basic functionsof the charting format (CQG’s TradeFlow) thatexploits the market transparency described and isused in this article for the purposes of illustration.The two elements (trades at the ask and trades atthe bid) of the TradeFlow bar are used as the basisfor an oscillator for the entry signals for onesystem. The basic TradeFlow bar uses the best bidas the low and the best ask price as the high forthe bar. For example, if the E-mini S&P futurescontract was 1515.75 bid and offered at 1516.00,the low of the TradeFlow bar is 1515.75 and thehigh is 1516.00.

The TradeFlow bar is colour-coded on apercentage basis by the amount of volumeexecuted at the ask price. If 400 contracts tradedat the 1516.00 offer and 100 contracts traded atthe 1515.75 bid, then the bar would be 80 percent green and 20 per cent red. The degree ofcolour brightness and the width of the bar arebased on the current bar’s executed volume relativeto the range of volume levels in a predeterminedlook back period. The higher the current bar’straded volume relative to the range of reportedtraded volumes, the brighter the colour and thewider the TradeFlow bar. Finally, time is not afactor in the TradeFlow bar building.

There are a number of key bits of informationgleaned from the TradeFlow bars. Wide and

018 � Automated Trader | Q3 2007

Automated traders now have access tounprecedented levels of market data.Thom Hartle, Director of Marketing,CQG, conducts a theoretical comparisonbetween two trading systems to explorehow order book data can be leveragedfor optimal trade performance.

Thom Hartle

Using Order Book Data to Improve AutomatedModel Performance

Page 3: Using Order Book Data - CQG Thom Hartle Reprinted from the July 2007 issue of Automated Trader Magazine Q3 2007 Using Order Book Data Improve Automated Model Performance

brightly-coloured TradeFlow bars denote highactivity price action. Thin and darkly colouredTradeFlow bars indicate low activity price action. Infact, a TradeFlow bar can have no volume (there is abid and ask price, but no trades) and the bar is gray.

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

Figure 1 is an example of a series of TradeFlow barscompared to classic one-minute open-high-low-closebars to illustrate the information available to thetrader using TradeFlow charts. The basic price bartells 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 inFigure 1 shows six nearly all-green TradeFlow barsfrom 1537.50 up to the high of 1538.75indicating aggressive buying. The top bar is almostall red, indicating traders came in and aggressivelyhit the 1538.50 bid. From there, the inside marketfalls and traders continued to hit bids.

At the bottom, the TradeFlow barsbetween 1536.50 bid and 1536.75ask are nearly all green as traderslifted offers. None of thisinformation is available from theregular price bars. You would nothave any reason to think the1538.75 price might be a short-term top in the price bar chart.

For this article, a three-tick rangeaggregation level is used. AllTradeFlow bars are three ticks inprice range. As long as the insidemarket does not move outside ofthe current three-tick range for the current TradeFlow bar, the bar continues to build based onany traded volume. Thisaggregation feature compresses the price action in a similarfashion to the classic point &figure charting style.

Q3 2007 | Automated Trader � 019

STRATEGIES

Figure 1: The basic TradeFlow bar’s high is the ask price and the low is the bid price of theinside market. The bar is colour-coded to reflect the percentage of volume traded at theask (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 open-high-low-close bar chart does not indicate any traded information other than last price.

Comparing the Trading Systems

In our market scenario, the two systems identify thetrend as either up or down, and then an oscillator isthe basis to indicate that a countertrend movement isunderway or complete. When the latter indicationoccurs, a trade is entered in the direction of themarket trend. The definition of the trend direction isthe 100-bar simple moving average is shifting higheror lower based on the one-bar difference. TradeSystem 1 uses the Moving Average Divergence

Convergence (MACD) study as the oscillator forgauging the countertrend movement. The classicMACD study is the difference between the 26- and13-bar exponential moving averages; a nine-barexponential 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-barexponential moving averages which are plotted ashistogram bars in Figure 2.

Copyright CQG Inc 2007

Page 4: Using Order Book Data - CQG Thom Hartle Reprinted from the July 2007 issue of Automated Trader Magazine Q3 2007 Using Order Book Data Improve Automated Model Performance

020 � Automated Trader | Q3 2007

If the MACD histogram bars are rising, then thedifference between the 13-bar and the 26-barexponential moving averages is climbing. If theMACD histogram bars are in positive territory, thenthe 13-bar is above the 26-bar exponential movingaverage. Moreover, if the MACD histogram bars arein negative territory, then the 13-bar is below the 26-bar exponential moving average. This situation is theprecursor to the buy signal.

The buy signal

If the one-bar difference of the 100-barsimple moving average is positive, the trend isup. If the MACD histogram bars are innegative territory and the one-bar difference isless negative than the previous one-bardifference (indicating momentum is shiftingupward), then buy at the opening of the nextTradeFlow bar (Figure 2).

A 1.50 point target is the profit objective forthe trade. For risk management, the stop lossused is a two-tick break below the low of theentry bar for long signals and a two-tick riseabove the high of the entry bar for shortpositions. Remember that the TradeFlow barcan only be three ticks’ range before a new

TradeFlow bar is generated. Therefore, once in atrade, the maximum loss is five ticks, but the stopcould be as close as just two ticks.

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

Some comments about Figure 2 are in order. First, thedouble arrows mark the TradeFlow bars to the MACDhistograms that qualify as the buy condition. The bluearrows on the TradeFlow bars mark the entry bar forthe long signal, which is the opening of the nextTradeFlow bar following the condition being met. Wedon’t know the condition is met until the TradeFlowbar closes, which occurs when the three-tick range isviolated and a new TradeFlow bar starts. The openingprice of the new TradeFlow bar is the trade. The solidblue line indicates the entry price. The dotted blue lineis the stop loss level and the X indicates the target pricewas 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. Thethird trade is more of a buying into upwardmomentum trade. The conditions for the third tradeare met on the same TradeFlow bar that met the exitrules of the second trade. An additional rule could beto only permit one signal per negative grouping of theMACD histograms during an uptrend.

Using order book data to improve automated model performance

Figure 2: The MHist study is the difference between the 13-barand the 26-bar exponential moving averages of the price (MACD).During an uptrend (signaled by the rising 100-bar SMA), the buysignal is when the MACD histogram bar climbs one bar while in

negative territory and there is no current trade.

Figure 3: The equity line for the system using the MACD oscillator is hit hardinitially, but recovers. Performance suffers when the market is moving

counter to the 100-bar simple moving average.

Copyright CQG Inc 2007

Copyright CQG Inc 2007

Page 5: Using Order Book Data - CQG Thom Hartle Reprinted from the July 2007 issue of Automated Trader Magazine Q3 2007 Using Order Book Data Improve Automated Model Performance

STRATEGIES

Q3 2007 | Automated Trader � 021

Figure 3 displays the performance of the tradingsystem from the May 30 through June 5, 2007.Table 1 details the system statistics. The equity linein Figure 3 initially moves well into negative territorybecause the gap down in price on the opening pullsthe moving average down and the system issues sellsignals, despite the price recovering from the earlyopening weakness. The sell signals were lagging theprice peaks during the recovery and the stops weresubsequently hit because the 1.50-point target wasnot being met. However, the equity line startsclimbing once the price action moved above therising moving average. The equity line then movesback and forth between positive and negativeterritory. The equity line tended to climb when themarket was above the rising moving average. Itappears that the standard MACD parameters workedbest under these conditions as the market tended tohit 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 oscillatoruses elements of the aggregated three-tick rangeTradeFlow bars. Each TradeFlow bar includes thevolume of trades at the ask price (buying) and thevolume of trades at the bid price (selling). Thisinformation was the basis for a study, here calledTradeFlow Cross, which is the source for the oscillatorfor the trading system.

Figure 4 shows the TradeFlow Cross study plotted inthe bottom pane. The green line is the five-bar runningsum of volume of contracts traded at the ask price (buyvolume). The red line is the five-bar running sum ofvolume of contracts traded at the bid price (sell

volume). The oscillator for the trading system isthe difference between the buy volume and thesell volume lines. In Figure 4, the price isinitially dropping and the sell volume line (red)is dominating the buy volume line (green).Then the market starts to climb and the buyvolume line climbs above the sell volume line.As the market advances however, the buyvolume line makes a lower peak than the firstpeak, indicating less trades going off at the askprice, and the market forms a short-term top.

The oscillator for Trade System 2 is displayed in themiddle pane: TradeFlow Volume Up minusTradeFlow Volume Down (TFUmTFD). Arrowsmark a turn up from negative territory by theoscillator and a turn down in positive territory.

The difference between the TFUmTFD oscillator andthe MACD is that the MACD is measuring the lastprice with no insight into whether the last price wasgenerated by a trader hitting the bid or lifting theoffer. The last price could be higher than the previousprice because the inside market climbed, howevertraders hit bids or sold into the higher bid to generatethe last price. The TFUmTFD study is onlymeasuring buying versus selling volume and is notchecking whether the last trade was higher or lower

Table 1: While the system did have some profitable runs, theresult was a net loss and only 34.78 per cent winners.

Total Net profit -287 Maximum Draw Duration 794

Closed Net profit -287 Max Consecutive Wins 4

Total trade Count 92 Current Consecutive Wins 0

Open position 0 Maximum consecutive losses 9

Percent Long 45 Current Consecutive Losses 1

Average Duration 4 Profit to Max Draw -0.55

Average Profit -3 Profit Loss Ratio 0.89

Average win 75 Percent Winners 34.78

Maximum Win 75 Remove to Neutral 0

Average Loss -45 Return Retracement -0.19

Maximum Loss -75 Linear Regression -0.02

Maximum Closed Drawdown -412 Time Percentage 25.48

Maximum Draw Amount -525 Current Drawdown -487

Figure 4: TradeFlow bars use traded volume at the ask price andat the bid price. These two elements are the basis for the

TradeFlow Cross study, which are the five-bar running sums ofthe traded volumes. The oscillator (middle pane) for the trading

system is the difference between the two TFCross curves.

Copyright CQG Inc 2007

Page 6: Using Order Book Data - CQG Thom Hartle Reprinted from the July 2007 issue of Automated Trader Magazine Q3 2007 Using Order Book Data Improve Automated Model Performance

022 � Automated Trader | Q3 2007

than the previous trade. Figure 5 shows two trades overthe same period as Figure 2, which had three trades.

The first trade in Figure 5 is one TradeFlow bar latecompared to the first trade in Figure 2. Thisoccurred because there was only one negativeTFUmTFD histogram bar during the congestion

period and two are required with the secondTFUmTFD histogram bar being less negative thanthe first. The third trade from Figure 2 did not occurin Figure 5 because the market was climbing withsteady buying (the TFUmTFD study was positive)over the rest of the chart.

Superior performance

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

Figure 6 shows that despite the gap downin price during the initial portion of thetest period, the sell signals tended tocatch the peaks of a few rallies andnetted out profits by hitting thedownside target despite the climbingprice action. This offset the losing shortsell trades as the market recovered fromthe gap down opening.

Once the moving average turned up, ledby the price action, the trading system(similar to the MACD oscillator signals)booked a number of winning trades. The

Using order book data to improve automated model performance

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 climbwhile in negative territory, the indication is there is a shift by

traders towards buying relative to selling.

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

Total Net profit 1137 Maximum Draw Duration 449

Closed Net profit 1137 Max Consecutive Wins 6

Total trade Count 101 Current Consecutive Wins 2

Open position 0 Maximum consecutive losses 4

Percent Long 54 Current Consecutive Losses 0

Average Duration 5 Profit to Max Draw 2.94

Average Profit 11 Profit Loss Ratio 1.47

Average win 74 Percent Winners 47.52

Maximum Win 75 Remove to Neutral 15.84

Average Loss -46 Return Retracement 1.77

Maximum Loss -75 Linear Regression 0.75

Maximum Closed Drawdown-187 Time Percentage 32.91

Maximum Draw Amount -387 Current Drawdown -125

Table 2: Using TradeFlow elements as the basis for an oscillator did lead to better performance compared to a

price-based oscillator. The system was profitableand the percentage of winners was 47.52 per cent.

Copyright CQG Inc 2007

Copyright CQG Inc 2007

Page 7: Using Order Book Data - CQG Thom Hartle Reprinted from the July 2007 issue of Automated Trader Magazine Q3 2007 Using Order Book Data Improve Automated Model Performance

Q3 2007 | Automated Trader � 023

STRATEGIES

trading system then tended to generate a sidewaysequity line similar to the MACD oscillator system.

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

Reality Check

Is it reasonable to compare two oscillators where oneis built on the difference between two exponentiallysmoothed moving averages of the price and the otheron the difference between the five-bar running sumof the traded bid and ask volumes? Figures 2 and 5did show one set of similar trades. Calculating thecorrelation coefficient between the two oscillator rawoutputs over the course of the test period showed a0.52 correlation. The results of running a rolling100-bar correlation between the two studies aredisplayed in Figure 7.

Figure 7 shows that thecorrelation between thetwo oscillators did attimes run at highlevels, having exceeded0.80 a number oftimes. This makessense in that tradesconsistently going offat the ask price or bidprice should lead tothe market trending,and the price-basedoscillator should run inthe same direction asthe traded volume-based oscillator. Onthe other hand, thetraded volume-basedoscillator did use afive-bar running sumas the core calculation,and this smallcalculation windowmay have made the

oscillator sensitive enough to be coincident with theend-points of countertrend moves. There was nooptimisation of parameters for this example, justanecdotal experience to set targets and stops. Theseparameters could be optimised and then in- and out-of-sample testing performed.

Finally, trading systems designed to buy pullbacks inuptrends and sell rallies in downtrends suffer drawdowns when the countertrend movement is eitherexcessive or actually part of a trend reversal. Anadditional rule could be to allow only one entrysignal per qualified crossover by the oscillator (i.e. onebuy signal when the oscillator is in negative territory).

Electronically-traded markets have opened up newareas of research through greater market transparency.Automated trading can now utilise marketinformation beyond just the last price. Besidesknowing whether a trader hit a bid or lifted an offer togenerate the last price, market data such as how theinside market was behaving, as well as ordermanagement by traders in the depth-of-market ladder,are now available as the basis for trading signals.

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

Copyright CQG Inc 2007

Page 8: Using Order Book Data - CQG Thom Hartle Reprinted from the July 2007 issue of Automated Trader Magazine Q3 2007 Using Order Book Data Improve Automated Model Performance

Reprinted from the July 2007 issue of Automated Trader Magazine www.automatedtrader.net