Algorithmic Trading Models — Breakouts
By: Dhruva Krishnamurthy
Tags: Algorithmic Trading, Trading, Algorithms, Forex, Commodities Trading

Breakout models are one of the most commonly used and discussed types of technical strategies because they build a trading methodology on top of the most fundamental technical analysis method, support, and resistance. They ultimately aim to profit off the price breaking through these levels, the theory being once they make that break, they will continue to move in that direction.

From an algorithmic trading point of view, it is fairly straightforward to decide when we enter a trade as we only have limited options available, each with its merits and issues. We could instruct a buy market order when the price closes above a resistance level or a sell market order when the price closes below support. In order to avoid false breakouts or fakeouts (when the price closes outside the support or resistance line but then reverses its direction, indicating that a breakout has not actually occurred) which market order might be prone to, we could place stop orders at a certain value below or above our S&R levels so that when we enter, we are sure that we have caught a breakout. The issue with this, naturally, is that we may already have missed a large part of the move by the time we enter the trade. In another scenario, we could wait for a second candle to confirm a breakout before entering the trade, but this gives us the same issue as the stop order method. We could also use a limit order, in which we expect the price to retract slightly back below the level before then continuing in its original direction. From a sentiment point of view, this strategy has some merit. Support and resistance levels are available to all traders, and many institutional ones, such as banks, may place large limit orders at these levels to try and sway a reversal. If a small reversal does happen before the breakout continues, then we benefit ourselves by entering a trade at a more optimal price. There are two obvious issues with this strategy, however. The first is that we hit a strong S&R level, and after bouncing off, the price continues to reverse, at which point we have entered a losing trade. The second is that the amount of traders pushing for a reversal at the level isn’t enough to bring the price back down to our limit level, leaving us with an unactivated limit order and a price traveling in the direction that we could have made a profit from had we entered the trade.

The far harder factor in determining in this scenario is establishing support and resistance levels. There are plenty of videos online that teach you how to observe and plot these levels visually. They begin by looking at the longer timeframe charts and moving to the shorter ones, iteratively plotting lines in which the prices appear to touch or come close to on at least 2 separate occasions. This, however, is not a method we can use in algorithmic trading because we want a purely objective method of identifying these levels.

Fig. 2 — The visual method for identifying S&R levels on the EUR/USD daily chart

There are a few ways in which we can do this. We can plot support as the lowest point and resistance as the highest point in the last x bars. Whilst this only entails one “price-touch,” it can be considered a slightly weaker level, suggesting that a breakout is more likely. Dynamic levels can also be employed, with a moving average that we hope the price will breakthrough. A third method is to create upper and lower bands, with Bollinger Bands, for example. In this case, when we see a bar break through one of the bands, we place a trade in the direction of the movement. If we want to specifically try and mimic the traditional visual methods of drawing S&R levels, we could consider some machine learning methods. A clustering algorithm that groups price levels could give us a good indication of where we place our lines (i.e., the x most frequent price clusters are considered key levels).

Fig. 3 — The typical S&R levels that might be plotted when looking for the maximum/minimum closing values in the last x bars

Fig. 4 — A strategy to use a 100 period Simple Moving Average (SMA) as a breakout level

Fig. 5 — A strategy to use Bollinger Bands as our dynamic breakout levels

There are many more variations to breakout models than I’ve described here, and adding complexity appears to be a necessity from the multiple fakeouts that we see in the graphs above, even if it is a small sample size. What we do have here, however, is a foundation on which to build on. The basic principle of breakout models is to define support and resistance levels and to place trades when these levels appear to be broken. The method of defining these levels, the type of trade entry to use, and what stops to place are all determined by exhaustive iteration, research, and testing. I have designed and backtested about 10 breakout models, and I will aim to outline a few in greater detail in coming articles, particularly on the coding side, so that you can see exactly how to produce these yourselves.